Resultant

Struct Resultant 

Source
pub struct Resultant<T> { /* private fields */ }
Expand description

“Resultant”结构是表示操作结果的通用类型,包含成功标志和可选数据或错误消息。

Properties:

  • success: “success”属性是一个布尔值,指示操作是否成功。如果“success”为“true”,则表示操作成功。如果“success”为“false”,则表示出现错误或失败。
  • data: “data”属性是一个可选字段,可以保存“T”类型的值。它用于存储成功操作的结果或输出。如果操作不成功或者没有结果返回,则“data”字段将设置为“None”。
  • error_msg: “error_msg”属性是一个可选的“String”,表示错误消息。它用于存储在执行函数或操作期间可能出现的任何错误消息。如果没有错误,“error_msg”的值为“None”。

Implementations§

Source§

impl<T> Resultant<T>
where T: Serialize,

Source

pub fn success(data: T) -> Json<Self>

函数“success”返回一个 JSON 对象,其中包含成功标志、数据,并且没有错误消息。

Arguments:

  • data: “data”参数的类型为“T”,这意味着它可以是任何类型。它表示将在响应中返回的数据。

Returns:

具有以下属性的 JSON 对象:

  • 成功:设置为 true
  • 数据:设置为提供的数据
  • error_msg:设置为无
Source

pub fn failure<E>(err: E) -> Json<Self>
where E: ToString,

函数“failure”返回一个 JSON 对象,其中“success”字段设置为“false”,“data”字段设置为“None”,“error_msg”字段设置为所提供错误的字符串表示形式。

Arguments:

  • err: 参数“err”的类型为“E”,它是实现“ToString”特征的泛型类型。它表示发生的错误,并将使用“ToString”特征的“to_string”方法转换为字符串。

Returns:

一个 Json<Self> 对象。

Trait Implementations§

Source§

impl<T: Clone> Clone for Resultant<T>

Source§

fn clone(&self) -> Resultant<T>

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<T: Debug> Debug for Resultant<T>

Source§

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

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

impl<'de, T> Deserialize<'de> for Resultant<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for Resultant<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Resultant<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Resultant<T>
where T: RefUnwindSafe,

§

impl<T> Send for Resultant<T>
where T: Send,

§

impl<T> Sync for Resultant<T>
where T: Sync,

§

impl<T> Unpin for Resultant<T>
where T: Unpin,

§

impl<T> UnwindSafe for Resultant<T>
where T: UnwindSafe,

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> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> 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<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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,