Skip to main content

RedisValue

Enum RedisValue 

Source
pub enum RedisValue {
    Nil,
    Int(i64),
    Float(f64),
    String(String),
    Bytes(Vec<u8>),
    Array(Vec<RedisValue>),
    Bool(bool),
}
Expand description

Redis 值类型

表示 Redis 中的各种数据类型,提供类型安全的值表示

Variants§

§

Nil

空值

§

Int(i64)

整数

§

Float(f64)

浮点数

§

String(String)

字符串

§

Bytes(Vec<u8>)

字节数组

§

Array(Vec<RedisValue>)

数组

§

Bool(bool)

布尔值

Implementations§

Source§

impl RedisValue

Source

pub fn as_string(&self) -> Option<String>

转换为字符串

§返回
  • Some(String): 如果值是字符串类型
  • None: 如果值不是字符串类型
§示例
use yang_db::RedisValue;

let value = RedisValue::String("hello".to_string());
assert_eq!(value.as_string(), Some("hello".to_string()));

let nil = RedisValue::Nil;
assert_eq!(nil.as_string(), None);
Source

pub fn as_i64(&self) -> Option<i64>

转换为整数

§返回
  • Some(i64): 如果值是整数类型
  • None: 如果值不是整数类型
Source

pub fn as_f64(&self) -> Option<f64>

转换为浮点数

§返回
  • Some(f64): 如果值是浮点数类型
  • None: 如果值不是浮点数类型
Source

pub fn as_bool(&self) -> Option<bool>

转换为布尔值

§返回
  • Some(bool): 如果值是布尔类型
  • None: 如果值不是布尔类型
Source

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

转换为字节数组引用

§返回
  • Some(&[u8]): 如果值是字节数组类型
  • None: 如果值不是字节数组类型
Source

pub fn as_array(&self) -> Option<&[RedisValue]>

转换为数组引用

§返回
  • Some(&[RedisValue]): 如果值是数组类型
  • None: 如果值不是数组类型
Source

pub fn is_nil(&self) -> bool

检查是否为 Nil

§返回
  • true: 如果值是 Nil
  • false: 如果值不是 Nil

Trait Implementations§

Source§

impl Clone for RedisValue

Source§

fn clone(&self) -> RedisValue

Returns a duplicate 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 RedisValue

Source§

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

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

impl From<&str> for RedisValue

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for RedisValue

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for RedisValue

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for RedisValue

Source§

fn from(bytes: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for RedisValue

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for RedisValue

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for RedisValue

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for RedisValue

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for RedisValue

Source§

fn eq(&self, other: &RedisValue) -> 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 StructuralPartialEq for RedisValue

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more