pub struct Encoding(/* private fields */);
Expand description
An encoding for String
.
Implementations§
Source§impl Encoding
impl Encoding
Sourcepub fn ascii_8bit() -> Encoding
pub fn ascii_8bit() -> Encoding
Returns the ASCII-8BIT
encoding.
§Examples
This is essentially an “anything goes” encoding:
use rosy::string::{String, Encoding};
let bytes: &[u8] = &[b'a', b'z', 0, 255];
let string = String::from(bytes);
assert_eq!(string.encoding(), Encoding::ascii_8bit());
Sourcepub fn utf8() -> Encoding
pub fn utf8() -> Encoding
Returns the UTF-8
encoding.
§Examples
use rosy::string::Encoding;
let utf8 = Encoding::find("UTF-8\0").unwrap();
assert_eq!(utf8, Encoding::utf8());
Sourcepub fn us_ascii() -> Encoding
pub fn us_ascii() -> Encoding
Returns the US-ASCII
encoding.
§Examples
use rosy::string::Encoding;
let ascii = Encoding::find("US-ASCII\0").unwrap();
assert_eq!(ascii, Encoding::us_ascii());
Sourcepub fn find<E>(encoding: E) -> Result<Self, EncodingLookupError>where
E: TryInto<Self, Error = EncodingLookupError>,
pub fn find<E>(encoding: E) -> Result<Self, EncodingLookupError>where
E: TryInto<Self, Error = EncodingLookupError>,
Attempts to find encoding
, returning an error if either:
encoding
cannot be passed in as a nul-terminated C string.- The requested encoding was not found.
§Examples
Looking up an encoding is straightforward since Rust allows for embedding nul bytes in its UTF-8 strings:
use rosy::string::Encoding;
let utf8 = Encoding::find("UTF-8\0").unwrap();
let ascii = Encoding::find("US-ASCII\0").unwrap();
assert_ne!(utf8, ascii);
Sourcepub fn name(&self) -> &CStr
pub fn name(&self) -> &CStr
Returns the encoding’s name.
§Examples
use rosy::string::Encoding;
assert_eq!(Encoding::utf8().name().to_bytes(), b"UTF-8");
Sourcepub fn is_ascii_8bit(self) -> bool
pub fn is_ascii_8bit(self) -> bool
Returns whether self
is ASCII-8BIT
.
Sourcepub fn is_us_ascii(self) -> bool
pub fn is_us_ascii(self) -> bool
Returns whether self
is US-ASCII
.
Sourcepub fn is_filesystem(self) -> bool
pub fn is_filesystem(self) -> bool
Returns whether self
is the filesystem encoding.
Sourcepub fn is_default_external(self) -> bool
pub fn is_default_external(self) -> bool
Returns whether self
is the default external encoding.
Sourcepub fn is_default_internal(self) -> bool
pub fn is_default_internal(self) -> bool
Returns whether self
is the default internal encoding.
Trait Implementations§
Source§impl Object for Encoding
impl Object for Encoding
Source§fn cast<A: Object>(obj: A) -> Option<Self>
fn cast<A: Object>(obj: A) -> Option<Self>
Attempts to create an instance by casting
obj
. Read moreSource§fn unique_id() -> Option<u128>
fn unique_id() -> Option<u128>
Returns a unique identifier for an object type to facilitate casting. Read more
Source§unsafe fn from_raw(raw: usize) -> Self
unsafe fn from_raw(raw: usize) -> Self
Creates a new object from
raw
without checking. Read moreSource§unsafe fn cast_unchecked(obj: impl Object) -> Self
unsafe fn cast_unchecked(obj: impl Object) -> Self
Casts
obj
to Self
without checking its type.Source§fn into_any_object(self) -> AnyObject
fn into_any_object(self) -> AnyObject
Returns
self
as an AnyObject
.Source§fn as_any_object(&self) -> &AnyObject
fn as_any_object(&self) -> &AnyObject
Returns a reference to
self
as an AnyObject
.Source§fn as_any_slice(&self) -> &[AnyObject]
fn as_any_slice(&self) -> &[AnyObject]
Returns
self
as a reference to a single-element slice.Source§unsafe fn as_unchecked<O: Object>(&self) -> &O
unsafe fn as_unchecked<O: Object>(&self) -> &O
Casts
self
to O
without checking whether it is one.Source§unsafe fn into_unchecked<O: Object>(self) -> O
unsafe fn into_unchecked<O: Object>(self) -> O
Converts
self
to O
without checking whether it is one.Source§fn singleton_class(self) -> Class<Self>
fn singleton_class(self) -> Class<Self>
Source§unsafe fn force_recycle(self)
unsafe fn force_recycle(self)
Forces the garbage collector to free the contents of
self
. Read moreSource§fn def_singleton_method<N, F>(self, name: N, f: F) -> Result
fn def_singleton_method<N, F>(self, name: N, f: F) -> Result
Defines a method for
name
on the singleton class of self
that calls
f
when invoked.Source§unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F)
unsafe fn def_singleton_method_unchecked<N, F>(self, name: N, f: F)
Source§unsafe fn call_with_protected(
self,
method: impl Into<SymbolId>,
args: &[impl Object],
) -> Result<AnyObject>
unsafe fn call_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>
Source§unsafe fn call_public_with(
self,
method: impl Into<SymbolId>,
args: &[impl Object],
) -> AnyObject
unsafe fn call_public_with( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> AnyObject
Source§unsafe fn call_public_with_protected(
self,
method: impl Into<SymbolId>,
args: &[impl Object],
) -> Result<AnyObject>
unsafe fn call_public_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>
Calls the public
method
on self
with args
and returns its output,
or an exception if one is raised. Read moreSource§fn is_eql<O: Object>(self, other: &O) -> bool
fn is_eql<O: Object>(self, other: &O) -> bool
Returns whether
self
is equal to other
in terms of the eql?
method.Source§fn get_attr<N: Into<SymbolId>>(self, name: N) -> AnyObject
fn get_attr<N: Into<SymbolId>>(self, name: N) -> AnyObject
Returns the value for the attribute of
self
associated with name
.impl Copy for Encoding
impl Eq for Encoding
Auto Trait Implementations§
impl Freeze for Encoding
impl RefUnwindSafe for Encoding
impl !Send for Encoding
impl !Sync for Encoding
impl Unpin for Encoding
impl UnwindSafe for Encoding
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