Skip to content

Commit

Permalink
fixed hasdocument
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph committed Oct 7, 2024
1 parent a50e06a commit 3c557d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions crates/gosub_html5/src/document/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub struct MyDocument<C: HasCssSystem + HasDocument> {
_marker: std::marker::PhantomData<C>,
}

impl<C: HasDocument> HasDocument for MyDocument<C> {
type Document = MyDocument<C>;
type Node = Node;
}
// impl<C: HasDocument> HasDocument for MyDocument<C> {
// type Document = MyDocument<C>;
// type Node = Node;
// }

impl<C: HasCssSystem + HasDocument> HasCssSystem for MyDocument<C> {
type CssStylesheet = C::CssStylesheet;
Expand All @@ -33,10 +33,10 @@ impl<C: HasCssSystem + HasDocument> HasCssSystem for MyDocument<C> {
type CssValue = C::CssValue;
}

impl<C: HasCssSystem> Document<C> for MyDocument<C> {
impl<C: HasCssSystem + HasDocument> Document<C> for MyDocument<C> {
type Node = Node;
type Query = Query;
type Document = Self<C>;
type Document = MyDocument<C>;

fn new(url: &str) -> Self {
let mut doc = Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<C: HasDocument, Q: Query> QueryProcessor<C, Q> {
Ok(found_ids)
}

fn matches_query_condition(&self, node_id: &NodeId, condition: &Q::Condition) -> bool {
fn matches_query_condition(&self, node_id: &NodeId, _condition: &Q::Condition) -> bool {
// This is just a mock implementation, we just return true for even node ids
node_id.id() % 2 == 0
}
Expand Down
18 changes: 9 additions & 9 deletions crates/gosub_shared/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ use std::cell::{Ref, RefCell, RefMut};
use std::rc::Rc;

#[derive(Debug)]
pub struct DocumentHandle<D: HasDocument>(pub Rc<RefCell<D>>);
pub struct DocumentHandle<C: HasDocument>(pub Rc<RefCell<C::Document>>);

impl<D: HasDocument> DocumentHandle<D> {
pub fn new(document: D) -> Self {
impl<C: HasDocument> DocumentHandle<C> {
pub fn new(document: C::Document) -> Self {
let handle = Self(Rc::new(RefCell::new(document)));

let mut binding = handle.clone().get_mut();
binding.set_handle(handle.clone());
let mut binding = handle.clone();
binding.get_mut().set_handle(handle.clone());

handle
}

pub fn get(&self) -> Ref<'_, D::Document> {
pub fn get(&self) -> Ref<'_, C::Document> {
self.0.borrow()
}

pub fn get_mut(&mut self) -> RefMut<'_, D::Document> {
pub fn get_mut(&mut self) -> RefMut<'_, C::Document> {
RefCell::borrow_mut(&self.0)
}
}

impl<D: HasDocument> Clone for DocumentHandle<D> {
impl<C: HasDocument> Clone for DocumentHandle<C> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}

impl<D: HasDocument> PartialEq for DocumentHandle<D> {
impl<C: HasDocument> PartialEq for DocumentHandle<C> {
fn eq(&self, other: &Self) -> bool {
Rc::ptr_eq(&self.0, &other.0)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/gosub_shared/src/traits/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub trait Document<C: HasCssSystem + HasDocument>: Sized {
position: Option<usize>,
) -> NodeId;

fn get_handle(&self) -> DocumentHandle<Self::Document>;
fn set_handle(&mut self, handle: DocumentHandle<Self::Document>);
fn get_handle(&self) -> DocumentHandle<C>;
fn set_handle(&mut self, handle: DocumentHandle<C>);

fn get_root_node(&self) -> Option<&Self::Node>;
fn get_node(&self, id: NodeId) -> Option<&Self::Node>;
Expand Down

0 comments on commit 3c557d4

Please sign in to comment.