Skip to main content

FixedText

Struct FixedText 

Source
pub struct FixedText<const N: usize> { /* private fields */ }
Expand description

A Text type which can store at most N bytes from a column.

The data is stored inline the type which typically means on the stack.

§Examples

use sqll::{Connection, FixedText, Result};

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE users (name TEXT);

    INSERT INTO users (name) VALUES ('Alice'), ('Bob');
"#)?;

let mut stmt = c.prepare("SELECT name FROM users")?;

let ids = stmt.iter::<FixedText<10>>().collect::<Result<Vec<_>>>()?;
assert_eq!(&ids[0], "Alice");
assert_eq!(&ids[1], "Bob");

Implementations§

Source§

impl<const N: usize> FixedText<N>

Source

pub const fn new() -> Self

Construct a new empty FixedText.

§Examples
use sqll::FixedText;

let s = FixedText::<5>::new();
assert_eq!(s.as_text(), "");
Source

pub const fn from_inner(inner: FixedBlob<N>) -> Self

Converts a vector of bytes to a String without checking that the string contains valid UTF-8.

§Examples
use sqll::{FixedBlob, FixedText};

let bytes = FixedBlob::<16>::try_from(&b"Hello World"[..])?;
let s = unsafe { FixedText::from_inner(bytes) };
assert_eq!(s.as_text(), "Hello World");
Source

pub fn as_text(&self) -> &Text

Coerce into the initialized string slice.

§Examples
use sqll::{Connection, FixedText};

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE users (name BLOB);

    INSERT INTO users (name) VALUES ('Alice'), ('Bob');
"#)?;

let mut stmt = c.prepare("SELECT name FROM users")?;

assert_eq! {
    stmt.iter::<FixedText<6>>().collect::<Vec<_>>(),
    [Ok(FixedText::<6>::try_from("Alice")?), Ok(FixedText::<6>::try_from("Bob")?)]
};

Methods from Deref<Target = Text>§

Source

pub fn as_bytes(&self) -> &[u8]

Get the underlying byte slice for this Text.

§Examples
use sqll::Text;

let t = Text::new(b"example");
assert_eq!(t.as_bytes(), b"example");
Source

pub fn to_str(&self) -> Result<&str, Utf8Error>

Attempt to convert this Text into a UTF-8 string slice.

Returns an error if the underlying bytes are not valid UTF-8.

§Examples
use sqll::Text;

let t = Text::new(b"example");
assert_eq!(t.to_str()?, "example");

let invalid = Text::new(b"\xF0\x90\x80");
assert!(invalid.to_str().is_err());

Trait Implementations§

Source§

impl<const N: usize> AsRef<Text> for FixedText<N>

Coerce into Text.

§Examples

use sqll::{FixedText, Text};

let text = FixedText::from(*b"example");
let text: &Text = text.as_ref();
assert_eq!(text, "example");
Source§

fn as_ref(&self) -> &Text

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

impl<const N: usize> Bind for FixedText<N>

Bind implementation for FixedText.

§Examples

use sqll::{Connection, FixedText};

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE users (name TEXT, age INTEGER);

    INSERT INTO users (name, age) VALUES ('Alice', 42), ('Bob', 30);
"#)?;

let mut stmt = c.prepare("SELECT age FROM users WHERE name = ?")?;

stmt.bind(FixedText::<5>::try_from("Alice")?)?;
assert_eq!(stmt.iter::<i64>().collect::<Vec<_>>(), [Ok(42)]);
Source§

fn bind(&self, stmt: &mut Statement) -> Result<()>

Bind this value into the given Statement.
Source§

impl<const N: usize> BindValue for FixedText<N>

BindValue implementation for FixedText.

§Examples

use sqll::{Connection, FixedText, Index};

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE users (name TEXT, age INTEGER);

    INSERT INTO users (name, age) VALUES ('Alice', 42), ('Bob', 30);
"#)?;

let mut stmt = c.prepare("SELECT age FROM users WHERE name = ?")?;

stmt.bind_value(Index::BIND, FixedText::<5>::try_from("Alice")?)?;
assert_eq!(stmt.iter::<i64>().collect::<Vec<_>>(), [Ok(42)]);
Source§

fn bind_value(&self, stmt: &mut Statement, index: Index) -> Result<()>

Bind a value to the specified parameter index. Read more
Source§

impl<const N: usize> Clone for FixedText<N>

Clone the FixedText<N>.

§Examples

use sqll::FixedText;

let ft1 = FixedText::<5>::try_from("Hello")?;
let ft2 = ft1.clone();
assert_eq!(ft1, ft2);
Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for FixedText<N>

Format as Text.

§Examples

use sqll::FixedText;

let ft = FixedText::<5>::try_from("Hello")?;
assert_eq!(format!("{:?}", ft), "\"Hello\"");
assert_eq!(format!("{}", ft), "Hello");
Source§

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

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

impl<const N: usize> Deref for FixedText<N>

Deref to Text.

§Examples

use sqll::FixedText;

let ft = FixedText::from(*b"invalid: \xF0\x90\x80\xF0\x90\x80");
assert_eq!(ft.as_bytes(), b"invalid: \xF0\x90\x80\xF0\x90\x80");
assert_eq!(ft.to_string(), "invalid: ��");
Source§

type Target = Text

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const N: usize> Display for FixedText<N>

The display implementation for Text will convert it into a UTF-8 string lossily, replacing invalid sequences with the replacement character .

§Examples

use sqll::FixedText;

let text = FixedText::from(b"before\xF0\x90\x80after");
assert_eq!(text.to_string(), "before�after");

let text = FixedText::from(b"before\xF0\x90\x80\xF0\x90\x80");
assert_eq!(text.to_string(), "before��");
Source§

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

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

impl<const N: usize> Eq for FixedText<N>

Source§

impl<const N: usize> From<&[u8; N]> for FixedText<N>

Attempt to convert a byte array into a FixedText<N>.

§Examples

use sqll::FixedText;

let ft = FixedText::from(b"Hello");
assert_eq!(ft.as_bytes(), b"Hello");
assert_eq!(ft.as_text(), "Hello");
Source§

fn from(value: &[u8; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<[u8; N]> for FixedText<N>

Attempt to convert a byte array into a FixedText<N>.

§Examples

use sqll::FixedText;

let ft = FixedText::from(*b"Hello");
assert_eq!(ft.as_text(), "Hello");
Source§

fn from(value: [u8; N]) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> FromColumn<'_> for FixedText<N>

FromColumn implementation for FixedBlob which reads at most N bytes.

If the column contains more than N bytes, a Code::MISMATCH error is returned.

§Examples

use sqll::{Connection, FixedText, Code};

let c = Connection::open_in_memory()?;

c.execute(r#"
    CREATE TABLE users (name TEXT);

    INSERT INTO users (name) VALUES ('Alice'), ('Bob');
"#)?;

let mut stmt = c.prepare("SELECT name FROM users")?;

assert!(stmt.step()?.is_row());
let bytes = stmt.column::<FixedText<5>>(0)?;
assert_eq!(bytes.as_text(), "Alice");

assert!(stmt.step()?.is_row());
let e = stmt.column::<FixedText<2>>(0).unwrap_err();
assert_eq!(e.code(), Code::MISMATCH);

let bytes = stmt.column::<FixedText<5>>(0)?;
assert_eq!(bytes.as_text(), "Bob");
Source§

type Type = Text

The type of a column. Read more
Source§

fn from_column(stmt: &Statement, index: Text) -> Result<Self>

Read a value from the specified column. Read more
Source§

impl<const N: usize> Hash for FixedText<N>

Hash the FixedText<N>.

§Examples

use sqll::FixedText;
use std::collections::HashSet;

let a = FixedText::<16>::try_from("Apple")?;
let b = FixedText::<16>::try_from("Banana")?;

let mut set = HashSet::from([a, b]);

let c = FixedText::<16>::try_from("Banana")?;
assert!(set.contains(&c));
assert!(!set.insert(c));
Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize> Ord for FixedText<N>

Compare for ordering.

§Examples

use sqll::FixedText;
use std::collections::BTreeSet;

let a = FixedText::<16>::try_from("Apple")?;
let b = FixedText::<16>::try_from("Banana")?;

let set = BTreeSet::from([a, b]);
Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const N: usize, const U: usize> PartialEq<FixedText<U>> for FixedText<N>

Compare the text for equality with another Text. This performs a byte-wise comparison.

§Examples

use sqll::FixedText;

let t1 = FixedText::from(*b"example");
let t2 = FixedText::from(*b"example");
let t3 = FixedText::from(*b"different");

assert_eq!(t1, t2);
assert_ne!(t1, t3);
Source§

fn eq(&self, other: &FixedText<U>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<const N: usize> PartialEq<Text> for FixedText<N>

Compare the text for equality with a Text. This performs a byte-wise comparison.

§Examples

use sqll::{FixedText, Text};

let t1 = FixedText::from(*b"example");
let t2 = Text::new("example");
let t3 = Text::new("different");

assert_eq!(t1, *t2);
assert_ne!(t1, *t3);
Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<const N: usize> PartialEq<str> for FixedText<N>

Compare the text for equality with a str. This performs a byte-wise comparison.

§Examples

use sqll::FixedText;

let t1 = FixedText::from(*b"example");
let t2 = "example";
let t3 = "different";

assert_eq!(t1, *t2);
assert_ne!(t1, *t3);
Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<const N: usize> PartialOrd for FixedText<N>

Compare for ordering.

§Examples

use sqll::FixedText;

let a = FixedText::<16>::try_from("Apple")?;
let b = FixedText::<16>::try_from("Banana")?;

assert!(a < b);
assert!(b > a);
Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> TryFrom<&[u8]> for FixedText<N>

Attempt to convert a byte slice into a FixedText<N>.

§Examples

use sqll::FixedText;

let ft = FixedText::<5>::try_from(&b"Hello"[..])?;
assert_eq!(ft.as_text(), "Hello");
Source§

type Error = CapacityError

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

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

Performs the conversion.
Source§

impl<const N: usize> TryFrom<&str> for FixedText<N>

Attempt to convert a string slice into a FixedText<N>.

§Examples

use sqll::FixedText;
let s = FixedText::<5>::try_from("Hello")?;
assert_eq!(s.as_text(), "Hello");
Source§

type Error = CapacityError

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

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

Performs the conversion.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for FixedText<N>

§

impl<const N: usize> RefUnwindSafe for FixedText<N>

§

impl<const N: usize> Send for FixedText<N>

§

impl<const N: usize> Sync for FixedText<N>

§

impl<const N: usize> Unpin for FixedText<N>

§

impl<const N: usize> UnsafeUnpin for FixedText<N>

§

impl<const N: usize> UnwindSafe for FixedText<N>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<'stmt, T> Row<'stmt> for T
where T: FromColumn<'stmt>,

Source§

fn from_row(stmt: &'stmt mut Statement) -> Result<T, Error>

Constructs an instance of Self from the given row.
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.