Struct Encoding

Source
pub struct Encoding(/* private fields */);
Expand description

An encoding for String.

Implementations§

Source§

impl Encoding

Source

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());
Source

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());
Source

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());
Source

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);
Source

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");
Source

pub fn is_ascii_8bit(self) -> bool

Returns whether self is ASCII-8BIT.

Source

pub fn is_utf8(self) -> bool

Returns whether self is UTF-8.

Source

pub fn is_us_ascii(self) -> bool

Returns whether self is US-ASCII.

Source

pub fn is_locale(self) -> bool

Returns whether self is the locale encoding.

Source

pub fn is_filesystem(self) -> bool

Returns whether self is the filesystem encoding.

Source

pub fn is_default_external(self) -> bool

Returns whether self is the default external encoding.

Source

pub fn is_default_internal(self) -> bool

Returns whether self is the default internal encoding.

Trait Implementations§

Source§

impl AsRef<AnyObject> for Encoding

Source§

fn as_ref(&self) -> &AnyObject

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Classify for Encoding

Source§

fn class() -> Class<Self>

Returns the typed class that can be used to get an instance of self.
Source§

impl Clone for Encoding

Source§

fn clone(&self) -> Encoding

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Encoding

Source§

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

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

impl Display for Encoding

Source§

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

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

impl From<Encoding> for AnyObject

Source§

fn from(object: Encoding) -> AnyObject

Converts to this type from the input type.
Source§

impl Object for Encoding

Source§

fn cast<A: Object>(obj: A) -> Option<Self>

Attempts to create an instance by casting obj. Read more
Source§

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

Creates a new object from raw without checking. Read more
Source§

unsafe fn cast_unchecked(obj: impl Object) -> Self

Casts obj to Self without checking its type.
Source§

fn into_any_object(self) -> AnyObject

Returns self as an AnyObject.
Source§

fn as_any_object(&self) -> &AnyObject

Returns a reference to self as an AnyObject.
Source§

fn as_any_slice(&self) -> &[AnyObject]

Returns self as a reference to a single-element slice.
Source§

fn raw(self) -> usize

Returns the raw object pointer.
Source§

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

Converts self to O without checking whether it is one.
Source§

fn id(self) -> u64

Returns the object’s identifier.
Source§

fn ty(self) -> Ty

Returns the virtual type of self.
Source§

fn is_ty(self, ty: Ty) -> bool

Returns whether the virtual type of self is ty.
Source§

fn class(self) -> Class<Self>

Returns the Class for self. Read more
Source§

fn singleton_class(self) -> Class<Self>

Returns the singleton Class of self, creating one if it doesn’t exist already. Read more
Source§

fn mark(self)

Marks self for Ruby to avoid garbage collecting it.
Source§

unsafe fn force_recycle(self)

Forces the garbage collector to free the contents of self. Read more
Source§

fn def_singleton_method<N, F>(self, name: N, f: F) -> Result
where N: Into<SymbolId>, F: MethodFn<Self>,

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)
where N: Into<SymbolId>, F: MethodFn<Self>,

Defines a method for name on the singleton class of self that calls f when invoked. Read more
Source§

unsafe fn call(self, method: impl Into<SymbolId>) -> AnyObject

Calls method on self and returns its output. Read more
Source§

unsafe fn call_protected(self, method: impl Into<SymbolId>) -> Result<AnyObject>

Calls method on self and returns its output, or an exception if one is raised. Read more
Source§

unsafe fn call_with( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> AnyObject

Calls method on self with args and returns its output. Read more
Source§

unsafe fn call_with_protected( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> Result<AnyObject>

Calls method on self with args and returns its output, or an exception if one is raised. Read more
Source§

unsafe fn call_public(self, method: impl Into<SymbolId>) -> AnyObject

Calls the public method on self and returns its output. Read more
Source§

unsafe fn call_public_protected( self, method: impl Into<SymbolId>, ) -> Result<AnyObject>

Calls the public method on self and returns its output, or an exception if one is raised. Read more
Source§

unsafe fn call_public_with( self, method: impl Into<SymbolId>, args: &[impl Object], ) -> AnyObject

Calls the public method on self with args and returns its output. Read more
Source§

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

fn inspect(self) -> String

Returns a printable string representation of self. Read more
Source§

fn to_s(self) -> String

Returns the result of calling the to_s method on self.
Source§

fn is_frozen(self) -> bool

Returns whether modifications can be made to self.
Source§

fn freeze(self)

Freezes self, preventing any further mutations.
Source§

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

Returns the value for the attribute of self associated with name.
Source§

unsafe fn eval(self, args: impl EvalArgs) -> AnyObject

Evaluates args in the context of self. Read more
Source§

unsafe fn eval_protected(self, args: impl EvalArgs) -> Result<AnyObject>

Evaluates args in the context of self, returning any raised exceptions. Read more
Source§

impl PartialEq<AnyObject> for Encoding

Source§

fn eq(&self, obj: &AnyObject) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Encoding

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for Encoding

Source§

type Error = EncodingLookupError

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

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&CStr> for Encoding

Source§

type Error = EncodingLookupError

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

fn try_from(s: &CStr) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&CString> for Encoding

Source§

type Error = EncodingLookupError

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

fn try_from(s: &CString) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&String> for Encoding

Source§

type Error = EncodingLookupError

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

fn try_from(s: &String) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Vec<u8>> for Encoding

Source§

type Error = EncodingLookupError

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

fn try_from(bytes: &Vec<u8>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Encoding

Source§

type Error = EncodingLookupError

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Encoding

Source§

impl Eq for Encoding

Auto Trait Implementations§

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<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
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.