pub struct CodeUnitString { /* private fields */ }Expand description
An exact sequence of UTF-16 code units.
Unlike String, this value admits lone surrogates. Conversion to scalar
Unicode is therefore explicit and checked.
Implementations§
Source§impl CodeUnitString
impl CodeUnitString
Sourcepub fn from_scalar(text: &str) -> Self
pub fn from_scalar(text: &str) -> Self
Encode scalar Unicode text as UTF-16 code units.
Sourcepub fn try_from_code_units(units: Vec<u16>) -> Result<Self, CodeUnitStringError>
pub fn try_from_code_units(units: Vec<u16>) -> Result<Self, CodeUnitStringError>
Preserve an exact sequence, rejecting an unrepresentable allocation.
Sourcepub fn from_code_units(units: Vec<u16>) -> Self
pub fn from_code_units(units: Vec<u16>) -> Self
Preserve an exact sequence including lone surrogates.
A Rust Vec<u16> that already exists necessarily satisfies the
allocation limit, so this compatibility constructor is infallible.
Sourcepub fn as_code_units(&self) -> &[u16]
pub fn as_code_units(&self) -> &[u16]
Borrow all exact code units.
Sourcepub fn code_unit_at(&self, offset: CodeUnitOffset) -> Option<u16>
pub fn code_unit_at(&self, offset: CodeUnitOffset) -> Option<u16>
Index one code unit.
Sourcepub fn slice(&self, range: CodeUnitRange) -> Self
pub fn slice(&self, range: CodeUnitRange) -> Self
Slice by a code-unit range, clamping both bounds.
Sourcepub fn code_units(&self) -> impl ExactSizeIterator<Item = u16> + '_
pub fn code_units(&self) -> impl ExactSizeIterator<Item = u16> + '_
Iterate exact code units (the indexing face).
Sourcepub fn iter_code_points(&self) -> CodePointIter<'_> ⓘ
pub fn iter_code_points(&self) -> CodePointIter<'_> ⓘ
Iterate chunks consisting of one surrogate pair or one unpaired unit.
Sourcepub fn to_scalar(&self) -> Result<String, CodeUnitStringError>
pub fn to_scalar(&self) -> Result<String, CodeUnitStringError>
Convert well-formed UTF-16 to scalar Unicode text.
Sourcepub fn code_unit_offset(
&self,
scalar: ScalarOffset,
) -> Result<CodeUnitOffset, OffsetConversionError>
pub fn code_unit_offset( &self, scalar: ScalarOffset, ) -> Result<CodeUnitOffset, OffsetConversionError>
Convert a bounded scalar offset to its code-unit offset.
Sourcepub fn scalar_offset(
&self,
code_unit: CodeUnitOffset,
) -> Result<ScalarOffset, OffsetConversionError>
pub fn scalar_offset( &self, code_unit: CodeUnitOffset, ) -> Result<ScalarOffset, OffsetConversionError>
Convert a bounded code-unit offset at a scalar boundary.
Trait Implementations§
Source§impl AsRef<[u16]> for CodeUnitString
impl AsRef<[u16]> for CodeUnitString
Source§impl Clone for CodeUnitString
impl Clone for CodeUnitString
Source§fn clone(&self) -> CodeUnitString
fn clone(&self) -> CodeUnitString
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CodeUnitString
impl Debug for CodeUnitString
Source§impl Default for CodeUnitString
impl Default for CodeUnitString
Source§fn default() -> CodeUnitString
fn default() -> CodeUnitString
impl Eq for CodeUnitString
Source§impl Hash for CodeUnitString
impl Hash for CodeUnitString
Source§impl Object for CodeUnitString
impl Object for CodeUnitString
Source§fn display(&self, _cx: &mut Cx) -> Result<String>
fn display(&self, _cx: &mut Cx) -> Result<String>
Source§fn header(&self) -> &ObjectHeader
fn header(&self) -> &ObjectHeader
Source§fn op(&self, _key: &OpKey) -> Option<&dyn Op>
fn op(&self, _key: &OpKey) -> Option<&dyn Op>
key, if any.Source§impl ObjectCompat for CodeUnitString
impl ObjectCompat for CodeUnitString
Source§fn as_expr(&self, _cx: &mut Cx) -> Result<Expr>
fn as_expr(&self, _cx: &mut Cx) -> Result<Expr>
Source§fn as_table(&self, cx: &mut Cx) -> Result<Value>
fn as_table(&self, cx: &mut Cx) -> Result<Value>
Source§fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
fn as_object_encoder(&self) -> Option<&dyn ObjectEncode>
Source§fn class(&self, cx: &mut Cx) -> Result<Value, Error>
fn class(&self, cx: &mut Cx) -> Result<Value, Error>
Source§fn as_callable(&self) -> Option<&dyn Callable>
fn as_callable(&self) -> Option<&dyn Callable>
Source§fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
fn as_read_constructor(&self) -> Option<&dyn ReadConstructor>
Source§fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
fn as_number_domain(&self) -> Option<&(dyn NumberDomain + 'static)>
Source§fn as_number_value(&self) -> Option<&dyn NumberValue>
fn as_number_value(&self) -> Option<&dyn NumberValue>
Source§fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
fn as_eval_fabric(&self) -> Option<&dyn EvalFabric>
Source§fn as_sequence(&self) -> Option<&dyn Sequence>
fn as_sequence(&self) -> Option<&dyn Sequence>
Source§fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
fn as_list(&self) -> Option<&(dyn ListValue + 'static)>
Source§fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
fn as_table_impl(&self) -> Option<&(dyn Table + 'static)>
Source§fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
fn as_dir(&self) -> Option<&(dyn Dir + 'static)>
Source§impl ObjectEncode for CodeUnitString
impl ObjectEncode for CodeUnitString
Source§fn object_encoding(&self, _cx: &mut Cx) -> Result<ObjectEncoding>
fn object_encoding(&self, _cx: &mut Cx) -> Result<ObjectEncoding>
ObjectEncoding this object should be rendered as.