Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/yew/src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod vtext;

use crate::html::{AnyScope, NodeRef};
use indexmap::IndexMap;
use std::borrow::Cow;
use std::{collections::HashMap, fmt, hint::unreachable_unchecked, iter};
use web_sys::{Element, Node};

Expand Down Expand Up @@ -83,6 +84,15 @@ impl From<Rc<str>> for AttrValue {
}
}

impl From<Cow<'static, str>> for AttrValue {
fn from(s: Cow<'static, str>) -> Self {
match s {
Cow::Borrowed(s) => s.into(),
Cow::Owned(s) => s.into(),
}
}
}

impl Clone for AttrValue {
fn clone(&self) -> Self {
match self {
Expand Down Expand Up @@ -152,6 +162,21 @@ mod tests_attr_value {
assert_eq!(av.into_string(), "Rc<str>");
}

#[test]
fn test_from_string() {
let av = AttrValue::from("str");
assert_eq!(av.into_string(), "str");

let av = AttrValue::from("String".to_string());
assert_eq!(av.into_string(), "String");

let av = AttrValue::from(Cow::from("BorrowedCow"));
assert_eq!(av.into_string(), "BorrowedCow");

let av = AttrValue::from(Cow::from("OwnedCow".to_string()));
assert_eq!(av.into_string(), "OwnedCow");
}

#[test]
fn test_equality() {
// construct 3 AttrValue with same embedded value; expectation is that all are equal
Expand Down