improve ergonomics of custom drivers and add a counter example to rink
This commit is contained in:
1 parent
b255800511
commit
ae1300b015
8 files changed
+338
-364
No files matched your search
@@ -62,6 +62,24 @@ pub struct OwnedAttributeDiscription {
|
||||
pub namespace: Option<String>,
|
||||
}
|
||||
|
||||
impl From<String> for OwnedAttributeDiscription {
|
||||
fn from(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
namespace: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Into<String>, N: Into<String>> From<(S, N)> for OwnedAttributeDiscription {
|
||||
fn from(name: (S, N)) -> Self {
|
||||
Self {
|
||||
name: name.0.into(),
|
||||
namespace: Some(name.1.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An attribute on a DOM node, such as `id="my-thing"` or
|
||||
/// `href="https://example.com"`.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -88,6 +106,36 @@ pub enum OwnedAttributeValue<V: FromAnyValue = ()> {
|
||||
Custom(V),
|
||||
}
|
||||
|
||||
impl From<String> for OwnedAttributeValue {
|
||||
fn from(value: String) -> Self {
|
||||
Self::Text(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f64> for OwnedAttributeValue {
|
||||
fn from(value: f64) -> Self {
|
||||
Self::Float(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<i64> for OwnedAttributeValue {
|
||||
fn from(value: i64) -> Self {
|
||||
Self::Int(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for OwnedAttributeValue {
|
||||
fn from(value: bool) -> Self {
|
||||
Self::Bool(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: FromAnyValue> From<V> for OwnedAttributeValue<V> {
|
||||
fn from(value: V) -> Self {
|
||||
Self::Custom(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Something that can be converted from a borrowed [Any] value.
|
||||
pub trait FromAnyValue: Clone + 'static {
|
||||
/// Convert from an [Any] value.
|
||||
|
||||
@@ -933,9 +933,11 @@ impl<V: FromAnyValue + Send + Sync> ElementNodeMut<'_, V> {
|
||||
/// Set an attribute in the element
|
||||
pub fn set_attribute(
|
||||
&mut self,
|
||||
name: OwnedAttributeDiscription,
|
||||
value: OwnedAttributeValue<V>,
|
||||
name: impl Into<OwnedAttributeDiscription>,
|
||||
value: impl Into<OwnedAttributeValue<V>>,
|
||||
) -> Option<OwnedAttributeValue<V>> {
|
||||
let name = name.into();
|
||||
let value = value.into();
|
||||
self.dirty_nodes.mark_dirty(
|
||||
self.id,
|
||||
NodeMaskBuilder::new()
|
||||
|
||||
Reference in new issue
Block a user