pub struct ArticleEnvelope {
pub schema_version: String,
pub payload: Value,
}Expand description
Schema version wrapper for forward compatibility.
Wraps API responses with schema version information. This allows applications to handle multiple schema versions and gracefully reject unsupported versions.
§Usage
use wme_models::ArticleEnvelope;
// Check if version is supported
let envelope = ArticleEnvelope::new("2024.2", serde_json::json!({"name": "Test"}));
assert!(envelope.is_supported());
// Parse the payload
let data: serde_json::Value = envelope.parse().unwrap();Fields§
§schema_version: StringSchema version (e.g., “2024.1”, “2024.2”)
payload: ValueRaw JSON payload
Implementations§
Source§impl ArticleEnvelope
impl ArticleEnvelope
Sourcepub fn parse<T>(&self) -> Result<T, ModelError>where
T: for<'de> Deserialize<'de>,
pub fn parse<T>(&self) -> Result<T, ModelError>where
T: for<'de> Deserialize<'de>,
Parse the payload into a typed struct.
§Type Parameters
T- The target type to deserialize into
§Errors
Returns an error if:
- The schema version is unsupported
- Deserialization fails
§Example
use wme_models::ArticleEnvelope;
let envelope = ArticleEnvelope::new(
"2024.2",
serde_json::json!({"name": "Test", "value": 42})
);
#[derive(serde::Deserialize)]
struct MyData { name: String, value: i32 }
let data: MyData = envelope.parse().unwrap();
assert_eq!(data.name, "Test");Sourcepub fn schema_version(&self) -> &str
pub fn schema_version(&self) -> &str
Get the schema version.
§Example
use wme_models::ArticleEnvelope;
let envelope = ArticleEnvelope::new("2024.2", serde_json::json!({}));
assert_eq!(envelope.schema_version(), "2024.2");Sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
Check if this envelope can be parsed.
Returns true if the schema version is in the supported list.
§Example
use wme_models::ArticleEnvelope;
let supported = ArticleEnvelope::new("2024.2", serde_json::json!({}));
assert!(supported.is_supported());
let unsupported = ArticleEnvelope::new("1999.1", serde_json::json!({}));
assert!(!unsupported.is_supported());Trait Implementations§
Source§impl Clone for ArticleEnvelope
impl Clone for ArticleEnvelope
Source§fn clone(&self) -> ArticleEnvelope
fn clone(&self) -> ArticleEnvelope
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ArticleEnvelope
impl Debug for ArticleEnvelope
Source§impl<'de> Deserialize<'de> for ArticleEnvelope
impl<'de> Deserialize<'de> for ArticleEnvelope
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 PartialEq for ArticleEnvelope
impl PartialEq for ArticleEnvelope
Source§impl Serialize for ArticleEnvelope
impl Serialize for ArticleEnvelope
impl StructuralPartialEq for ArticleEnvelope
Auto Trait Implementations§
impl Freeze for ArticleEnvelope
impl RefUnwindSafe for ArticleEnvelope
impl Send for ArticleEnvelope
impl Sync for ArticleEnvelope
impl Unpin for ArticleEnvelope
impl UnsafeUnpin for ArticleEnvelope
impl UnwindSafe for ArticleEnvelope
Blanket Implementations§
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