[][src]Struct jomini::Scalar

pub struct Scalar<'a> { /* fields omitted */ }

Single value encapsulating windows-1252 data.

Since windows-1252 is a single byte character encoding, a scalar will never fail to be created.

use jomini::Scalar;

let v1 = Scalar::new(b"a");
assert_eq!(v1.to_utf8(), "a");

Implementations

impl<'a> Scalar<'a>[src]

pub fn new(data: &'a [u8]) -> Scalar<'a>[src]

Create a new scalar backed by windows-1252 encoded byte slice

pub fn view_data(&self) -> &[u8][src]

View the underlying windows-1252 encoded data

pub fn to_f64(&self) -> Result<f64, ScalarError>[src]

Try converting the scalar to f64

pub fn to_bool(&self) -> Result<bool, ScalarError>[src]

Try converting the scalar to f64

pub fn to_i64(&self) -> Result<i64, ScalarError>[src]

Try converting the scalar to i64

pub fn to_u64(&self) -> Result<u64, ScalarError>[src]

Try converting the scalar to u64

pub fn to_utf8(&self) -> Cow<'a, str>[src]

Convert scalar data into utf8. Will allocate if the string is not utf8.

use jomini::Scalar;

let v1 = Scalar::new(b"a");
assert_eq!(v1.to_utf8(), "a");

let v2 = Scalar::new(&[255][..]);
assert_eq!(v2.to_utf8(), "ÿ");

pub fn to_utf8_owned(&self) -> String[src]

Convert scalar data into an owned string

use jomini::Scalar;

let v1 = Scalar::new(b"a");
assert_eq!(v1.to_utf8(), String::from("a"));

let v2 = Scalar::new(&[255][..]);
assert_eq!(v2.to_utf8(), String::from("ÿ"));

pub fn is_ascii(&self) -> bool[src]

Returns if the scalar contains only ascii values

use jomini::Scalar;

let v1 = Scalar::new(b"a");
assert!(v1.is_ascii());

let v2 = Scalar::new(&[255][..]);
assert!(!v2.is_ascii());

Trait Implementations

impl<'a> Clone for Scalar<'a>[src]

impl<'a> Copy for Scalar<'a>[src]

impl<'a> Debug for Scalar<'a>[src]

impl<'a> Display for Scalar<'a>[src]

impl<'a> PartialEq<Scalar<'a>> for Scalar<'a>[src]

impl<'a> StructuralPartialEq for Scalar<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Scalar<'a>

impl<'a> Send for Scalar<'a>

impl<'a> Sync for Scalar<'a>

impl<'a> Unpin for Scalar<'a>

impl<'a> UnwindSafe for Scalar<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.