pub struct String<A: IVm>(/* private fields */);Expand description
use nanvm_lib::{
vm::{String, IVm, Any, ToString, ToAny},
common::sized_index::SizedIndex,
naive::Naive,
};
fn string_test<A: IVm>() {
let a: String<A> = "Hello, world!".into();
assert_eq!(a.length(), 13);
assert_eq!(a[12], '!' as u16);
let b: String<A> = ['H' as u16, 'i' as u16, '!' as u16].to_string();
let c = a.clone() + b;
let ac: Any<A> = c.to_any();
let d: String<A> = ac.try_into().unwrap();
assert_eq!(d.length(), 16);
assert_eq!(format!("{d:?}"), r#""Hello, world!Hi!""#);
assert_eq!(char::decode_utf16(d.clone()).map(Result::unwrap).collect::<std::string::String>(), "Hello, world!Hi!");
let n = "Hello, world!Hi!".into();
assert_eq!(d, n);
assert_eq!(d, d);
assert_ne!(d, a);
}
string_test::<Naive>();Implementations§
Trait Implementations§
Source§impl<A: IVm> AddAssign for String<A>
impl<A: IVm> AddAssign for String<A>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreimpl<A: IVm> Eq for String<A>
Source§impl<A: IVm> From<String<A>> for String
Lossy: a lone surrogate, which a JavaScript string may hold and a Rust
string cannot, becomes U+FFFD. Use char::decode_utf16 directly where a
lone surrogate must be told apart from a real U+FFFD.
impl<A: IVm> From<String<A>> for String
Lossy: a lone surrogate, which a JavaScript string may hold and a Rust
string cannot, becomes U+FFFD. Use char::decode_utf16 directly where a
lone surrogate must be told apart from a real U+FFFD.
Source§impl<A: IVm> IntoIterator for String<A>
impl<A: IVm> IntoIterator for String<A>
Source§impl<A: IVm> Ord for String<A>
impl<A: IVm> Ord for String<A>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<A: IVm> PartialOrd for String<A>
Lexicographic order by UTF-16 code unit — String::lessThan, the rule
< uses when both operands are strings. Not codepoint-aware: a
surrogate pair is compared unit by unit, the same as any other pair of
code units, never combined into one codepoint first.
impl<A: IVm> PartialOrd for String<A>
Lexicographic order by UTF-16 code unit — String::lessThan, the rule
< uses when both operands are strings. Not codepoint-aware: a
surrogate pair is compared unit by unit, the same as any other pair of
code units, never combined into one codepoint first.
Auto Trait Implementations§
impl<A> Freeze for String<A>
impl<A> RefUnwindSafe for String<A>
impl<A> Send for String<A>
impl<A> Sync for String<A>
impl<A> Unpin for String<A>
impl<A> UnsafeUnpin for String<A>
impl<A> UnwindSafe for String<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more