[][src]Trait abin::StrFactory

pub trait StrFactory {
    type TBinFactory: BinFactory;
    fn from_segments<'a>(
        iter: impl SegmentIterator<StrSegment<'a, <Self::TBinFactory as BinFactory>::T>>
    ) -> AnyStr<<Self::TBinFactory as BinFactory>::T> { ... }
fn from_segment<'a>(
        segment: impl Into<StrSegment<'a, <Self::TBinFactory as BinFactory>::T>>
    ) -> AnyStr<<Self::TBinFactory as BinFactory>::T> { ... }
fn from_utf8_iter(
        iter: impl IntoIterator<Item = u8>
    ) -> FromUtf8IterResult<<Self::TBinFactory as BinFactory>::T> { ... }
fn empty() -> AnyStr<<Self::TBinFactory as BinFactory>::T> { ... }
fn from_static(
        string: &'static str
    ) -> AnyStr<<Self::TBinFactory as BinFactory>::T> { ... }
fn from_given_string(
        string: impl Into<String>
    ) -> AnyStr<<Self::TBinFactory as BinFactory>::T> { ... }
fn copy_from_str<'a>(
        string: impl Into<&'a str>
    ) -> AnyStr<<Self::TBinFactory as BinFactory>::T> { ... } }

Use this factory to create strings. There's a built-in implementation in this crate; custom implementations (that implement this trait) are possible.

Associated Types

type TBinFactory: BinFactory

The binary backend this string factory uses to produce strings (strings are just wrappers for utf-8-validated binaries).

Loading content...

Provided methods

fn from_segments<'a>(
    iter: impl SegmentIterator<StrSegment<'a, <Self::TBinFactory as BinFactory>::T>>
) -> AnyStr<<Self::TBinFactory as BinFactory>::T>

Create a string by joining multiple segments (see StrSegment).

use abin::{StrSegment, SegmentsSlice, Str, NewStr, StrFactory, StrBuilder};
let segments = &mut [StrSegment::Static("Hello, "),
    StrSegment::Static("World!")];
let iterator = SegmentsSlice::new(segments);
let str : Str = NewStr::from_segments(iterator);
assert_eq!("Hello, World!", str.as_str());

fn from_segment<'a>(
    segment: impl Into<StrSegment<'a, <Self::TBinFactory as BinFactory>::T>>
) -> AnyStr<<Self::TBinFactory as BinFactory>::T>

Convert a StrSegment to a string.

use abin::{StrSegment, NewStr, StrFactory};

// both lines are equivalent (`from_segment` will just call `from_static`).
let str_1 = NewStr::from_static("Hello");
let str_2 = NewStr::from_segment(StrSegment::Static("Hello"));

assert_eq!(str_1, str_2);

fn from_utf8_iter(
    iter: impl IntoIterator<Item = u8>
) -> FromUtf8IterResult<<Self::TBinFactory as BinFactory>::T>

Create a string from an iterator. To be efficient, the iterator should provide correct hints (see Iterator::size_hint).

use abin::{NewStr, Str, StrFactory};
let str : Str = NewStr::from_utf8_iter((65..72).map(|i| i as u8)).unwrap();
assert_eq!("ABCDEFG", str.as_str());

fn empty() -> AnyStr<<Self::TBinFactory as BinFactory>::T>

Empty string.

use abin::{NewStr, StrFactory, Str};
let str : Str = NewStr::empty();
assert_eq!(0, str.len());

fn from_static(
    string: &'static str
) -> AnyStr<<Self::TBinFactory as BinFactory>::T>

A string from a &'static str.

use abin::{Str, NewStr, StrFactory};
let str : Str = NewStr::from_static("Hello");
assert_eq!("Hello", str.as_str());

fn from_given_string(
    string: impl Into<String>
) -> AnyStr<<Self::TBinFactory as BinFactory>::T>

Creates a string from given String. Important: Only use this method if you're given a String from outside (something you can't control). If you're in control, use any of the other methods provided by this factory (such as from_iter, from_segments).

use abin::{Str, NewStr, StrFactory};
let some_string : String = "This is some text".to_owned();
let str : Str = NewStr::from_given_string(some_string);
assert_eq!("This is some text", str.as_str());

fn copy_from_str<'a>(
    string: impl Into<&'a str>
) -> AnyStr<<Self::TBinFactory as BinFactory>::T>

A string from a &str; prefer from_static if there's a static lifetime.

use abin::{Str, NewStr, StrFactory};
let str : Str = NewStr::copy_from_str("Hello");
assert_eq!("Hello", str.as_str());
Loading content...

Implementors

impl StrFactory for NewSStr[src]

impl StrFactory for NewStr[src]

Loading content...