Struct GStr

Source
pub struct GStr { /* private fields */ }
Expand description

estructura que envuelve la cadena de manera segura y evita la duplicación de la cadena.

use g_str::GStr;
fn main() {
    let cadena = GStr::new("hola");
}

GStr utiliza un contador de referencias para gestionar la vida útil de las cadenas (Similar a lo que hace la estructura Rc). Esto significa que cada vez que una nueva variable hace referencia a una cadena, el contador de referencias aumenta. Cuando una variable deja de usar la cadena, el contador disminuye.

Implementations§

Source§

impl GStr

Source

pub fn new<T: StringInfo>(strn: T) -> GStr

Esta función realiza una búsqueda en las cadenas previamente creadas para encontrar una que coincida con la cadena recibida.

  • Si la cadena existe, la función te devuelve un GStr que apunta a esa cadena existente.
  • Si la cadena no existe, la función crea una nueva cadena y te devuelve un GStr que apunta a esta nueva cadena.
Source

pub fn chars_count(&self) -> usize

Esta función devuelve la cantidad de caracteres que contiene la cadena.

Trait Implementations§

Source§

impl AsRef<str> for GStr

Source§

fn as_ref(&self) -> &str

Esta función retorna una referencia inmutable a la cadena.

Source§

impl Clone for GStr

Source§

fn clone(&self) -> Self

Clona el GStr. No crea una copia de la cadena, simplemente crea un nuevo GStr que apunta a la cadena existente.

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Display for GStr

Source§

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

permite imprimir el GStr en una cadena directamente sin acceder a la cadena.

use g_str::GStr;
fn main() {
    let nombre = GStr::new("hola");
    println!("hola {nombre}");
}
Source§

impl Drop for GStr

Source§

fn drop(&mut self)

funcion para determinar si eliminar la cadena.

Source§

impl PartialEq for GStr

Source§

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

sobrecarga al operador == para ver si dos cadenas son las mismas, comparando su ubicacion de memoria, es decir, comparar dos referencias en vez de hacer un analisis caracter por caracter.

Source§

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

igual que lo anterior, pero sobrecargando el operador != para ver si dos cadenas son diferentes

Auto Trait Implementations§

§

impl Freeze for GStr

§

impl RefUnwindSafe for GStr

§

impl !Send for GStr

§

impl !Sync for GStr

§

impl Unpin for GStr

§

impl UnwindSafe for GStr

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<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.