Skip to main content

String

Struct String 

Source
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§

Source§

impl<A: IVm> String<A>

Source

pub fn from_char_code(args: Array<A>) -> Result<Self, Any<A>>

String.fromCharCode(...args): ToUint16 of each argument, in order. Code units are preserved, including unpaired surrogates.

Trait Implementations§

Source§

impl<A: IVm> Add for String<A>

Source§

type Output = String<A>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<A: IVm> AddAssign for String<A>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<A: Clone + IVm> Clone for String<A>

Source§

fn clone(&self) -> String<A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: IVm> Debug for String<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: IVm> Default for String<A>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<A: IVm> Eq for String<A>

Source§

impl<A: IVm> From<&str> for String<A>

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> From<String<A>> for Unpacked<A>

Source§

fn from(value: String<A>) -> Self

Converts to this type from the input type.
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.

Source§

fn from(value: String<A>) -> Self

Converts to this type from the input type.
Source§

impl<A: IVm> Index<u32> for String<A>

Source§

fn index(&self, index: u32) -> &Self::Output

Currently panics if out of bounds. TODO: Future versions may change to return Result<u16, Any<A>>. Also we can implement Index<Any<A>>, Index<f64> and Index<String16>.

Source§

type Output = u16

The returned type after indexing.
Source§

impl<A: IVm> IntoIterator for String<A>

Source§

type Item = u16

The type of the elements being iterated over.
Source§

type IntoIter = IndexIter<u32, String<A>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<A: IVm> Ord for String<A>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<A: IVm> PartialEq for String<A>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. 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.

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<A: IVm> TryFrom<Any<A>> for String<A>

Source§

type Error = Any<A>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Any<A>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<A> Freeze for String<A>
where <A as IVm>::InternalString: Freeze,

§

impl<A> RefUnwindSafe for String<A>

§

impl<A> Send for String<A>
where <A as IVm>::InternalString: Send,

§

impl<A> Sync for String<A>
where <A as IVm>::InternalString: Sync,

§

impl<A> Unpin for String<A>
where <A as IVm>::InternalString: Unpin,

§

impl<A> UnsafeUnpin for String<A>

§

impl<A> UnwindSafe for String<A>
where <A as IVm>::InternalString: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> SizedIndex<u32> for W
where W: ContainerWrapper,

Source§

fn length(&self) -> u32

Source§

fn is_empty(&self) -> bool

Source§

fn last(&self) -> Option<&Self::Output>

Source§

fn index_iter(self) -> IndexIter<I, Self> ⓘ
where Self: Sized,

Source§

impl<T> ToAny for T

Source§

fn to_any<A: IVm>(self) -> Any<A>
where Self: Into<Unpacked<A>>,

Source§

impl<T> ToArray for T

Source§

fn to_array<A: IVm>(self) -> Array<A>
where Self: Sized + IntoIterator<Item = Any<A>>,

Source§

impl<T> ToObject for T

Source§

fn to_object<A: IVm>(self) -> Object<A>
where Self: Sized + IntoIterator<Item = Property<A>>,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T

Source§

fn try_to_string<A: IVm>(self) -> Result<String<A>, Any<A>>
where Self: Sized + IntoIterator<Item = Result<u16, Any<A>>>,

Source§

fn to_string<A: IVm>(self) -> String<A>
where Self: Sized + IntoIterator<Item = u16>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.