#[repr(C)]pub struct UStatus { /* private fields */ }Expand description
Operation status: a UCode with optional message and details.
Implementations§
Source§impl UStatus
impl UStatus
Sourcepub fn ok() -> Self
pub fn ok() -> Self
Creates a status representing a success.
§Examples
use up_rust::{UCode, UStatus};
let status = UStatus::ok();
assert_eq!(status.code(), UCode::Ok);Sourcepub fn fail_with_code<M: Into<String>>(code: UCode, msg: M) -> Self
pub fn fail_with_code<M: Into<String>>(code: UCode, msg: M) -> Self
Creates a status representing a failure.
§Examples
use up_rust::{UCode, UStatus};
let status = UStatus::fail_with_code(UCode::DataLoss, "something went wrong");
assert_eq!(status.code(), UCode::DataLoss);
assert_eq!(status.message().unwrap(), "something went wrong");Sourcepub fn new<M: Into<String>>(
code: UCode,
msg: Option<M>,
details: Option<Vec<UAny>>,
) -> Self
pub fn new<M: Into<String>>( code: UCode, msg: Option<M>, details: Option<Vec<UAny>>, ) -> Self
Creates a status from a code and an optional message.
§Examples
use up_rust::{UCode, UStatus};
let status = UStatus::new(UCode::DataLoss, Some("something went wrong"), None);
assert_eq!(status.code(), UCode::DataLoss);
assert_eq!(status.message().unwrap(), "something went wrong");
assert!(status.details().is_empty());Sourcepub fn is_failed(&self) -> bool
pub fn is_failed(&self) -> bool
Checks if this status represents a failure.
§Examples
use up_rust::{UCode, UStatus};
let failed_status = UStatus::fail_with_code(UCode::Internal, "something went wrong");
assert!(failed_status.is_failed());
let succeeded_status = UStatus::ok();
assert!(!succeeded_status.is_failed());Sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
Checks if this status represents a success.
§Examples
use up_rust::{UCode, UStatus};
let succeeded_status = UStatus::ok();
assert!(succeeded_status.is_success());
let failed_status = UStatus::fail_with_code(UCode::Internal, "something went wrong");
assert!(!failed_status.is_success());Sourcepub fn message(&self) -> Option<&str>
pub fn message(&self) -> Option<&str>
Gets this status’ error message.
§Returns
an empty string if this instance has been created without a message.
§Examples
use up_rust::{UCode, UStatus};
let failed_status = UStatus::fail_with_code(UCode::Internal, "my error message");
assert_eq!(failed_status.message(), Some("my error message"));
let succeeded_status = UStatus::ok();
assert!(succeeded_status.message().is_none());Sourcepub fn get_message(&self) -> Option<&str>
👎Deprecated since 0.11.0: renamed to message
pub fn get_message(&self) -> Option<&str>
messageDeprecated alias for Self::message.
Sourcepub fn message_or_default<'a>(&'a self, default: &'a str) -> &'a str
pub fn message_or_default<'a>(&'a self, default: &'a str) -> &'a str
Gets this status’ error message or a default value if none is set.
§Arguments
default- The default value to return if this status has no message.
§Returns
the error message if set, otherwise the provided default value.
§Examples
use up_rust::{UCode, UStatus};
let failed_status = UStatus::fail_with_code(UCode::Internal, "my error message");
assert_eq!(failed_status.message_or_default("default"), "my error message");
let succeeded_status = UStatus::ok();
assert_eq!(succeeded_status.message_or_default("default"), "default");Sourcepub fn get_message_or_default<'a>(&'a self, default: &'a str) -> &'a str
👎Deprecated since 0.11.0: renamed to message_or_default
pub fn get_message_or_default<'a>(&'a self, default: &'a str) -> &'a str
message_or_defaultDeprecated alias for Self::message_or_default.
Sourcepub fn code(&self) -> UCode
pub fn code(&self) -> UCode
Gets this status’ error code.
§Examples
use up_rust::{UCode, UStatus};
let status_with_code = UStatus::fail_with_code(UCode::Internal, "my error message");
assert_eq!(status_with_code.code(), UCode::Internal);Sourcepub fn get_code(&self) -> UCode
👎Deprecated since 0.11.0: renamed to code
pub fn get_code(&self) -> UCode
codeDeprecated alias for Self::code.
Sourcepub fn details(&self) -> &[UAny]
pub fn details(&self) -> &[UAny]
Gets this status’ details.
§Examples
use up_rust::{UAny, UCode, UStatus};
let details = vec![UAny::new("type.googleapis.com/google.protobuf.StringValue".to_string(), b"the string".as_ref())];
let status_with_details = UStatus::new(UCode::Internal, Some("my error message"), Some(details.clone()));
assert_eq!(status_with_details.details(), details.as_slice());
let status_without_details = UStatus::fail_with_code(UCode::Internal, "my error message");
assert!(status_without_details.details().is_empty());Sourcepub fn get_details(&self) -> &[UAny]
👎Deprecated since 0.11.0: renamed to details
pub fn get_details(&self) -> &[UAny]
detailsDeprecated alias for Self::details.
Trait Implementations§
Source§impl Error for UStatus
impl Error for UStatus
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<ServiceInvocationError> for UStatus
impl From<ServiceInvocationError> for UStatus
Source§fn from(value: ServiceInvocationError) -> Self
fn from(value: ServiceInvocationError) -> Self
Converts to this type from the input type.
Source§impl From<UStatus> for RegistrationError
impl From<UStatus> for RegistrationError
Source§impl From<UStatus> for ServiceInvocationError
impl From<UStatus> for ServiceInvocationError
Source§impl From<UWireError> for UStatus
impl From<UWireError> for UStatus
Source§fn from(value: UWireError) -> Self
fn from(value: UWireError) -> Self
Converts to this type from the input type.
Source§impl From<UWireMetadataError> for UStatus
impl From<UWireMetadataError> for UStatus
Source§fn from(value: UWireMetadataError) -> Self
fn from(value: UWireMetadataError) -> Self
Converts to this type from the input type.
Source§impl ProtobufMappable for UStatus
impl ProtobufMappable for UStatus
Source§fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>
fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>
Parses an instance of this type from the given protobuf bytes. Read more
Source§fn parse_from_packed_protobuf_bytes(
proto: &[u8],
) -> Result<Self, SerializationError>
fn parse_from_packed_protobuf_bytes( proto: &[u8], ) -> Result<Self, SerializationError>
Parses an instance of this type from the given packed protobuf bytes. Read more
Source§fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
Serializes this instance to protobuf bytes. Read more
Source§fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
Serializes this instance to packed protobuf bytes. Read more
impl StructuralPartialEq for UStatus
Auto Trait Implementations§
impl Freeze for UStatus
impl RefUnwindSafe for UStatus
impl Send for UStatus
impl Sync for UStatus
impl Unpin for UStatus
impl UnwindSafe for UStatus
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<TCore> UWithNativePrefixWire for TCore
impl<TCore> UWithNativePrefixWire for TCore
Source§fn into_native_prefix_wire_transport<W>(
self,
wire: W,
) -> UWireTransport<TCore, W, NativePrefixFrameMetadataCodec>where
W: UWire,
fn into_native_prefix_wire_transport<W>(
self,
wire: W,
) -> UWireTransport<TCore, W, NativePrefixFrameMetadataCodec>where
W: UWire,
Wraps this core with an external or custom selected wire using canonical metadata.
Source§fn into_protobuf_transport(
self,
) -> UWireTransport<TCore, ProtobufWire, NativePrefixFrameMetadataCodec>
fn into_protobuf_transport( self, ) -> UWireTransport<TCore, ProtobufWire, NativePrefixFrameMetadataCodec>
Wraps this core with the Protocol Buffers selected-wire profile.
Source§fn into_stable_container_transport(
self,
) -> UWireTransport<TCore, StableContainerWireFormat, NativePrefixFrameMetadataCodec>
fn into_stable_container_transport( self, ) -> UWireTransport<TCore, StableContainerWireFormat, NativePrefixFrameMetadataCodec>
Wraps this core with the stable-container selected-wire profile.