Trait hedwig::validators::prost::SchemaMatcher [−][src]
pub trait SchemaMatcher<MessageType> {
type InvalidSchemaError;
fn try_match_schema(
&self,
schema: &str
) -> Result<(), Self::InvalidSchemaError>;
}
This is supported on crate feature
prost
only.Expand description
A means of asserting that an incoming message’s schema
matches
a given message type’s deserialized format.
use hedwig::validators::prost::SchemaMatcher;
struct MyMessage {
// ...
}
// SchemaMatcher has a blanket impl over closures
let my_matcher = |schema: &str| {
// imagine some rudimentary version check
if schema.starts_with("messages/my-message/my-schema-")
&& (schema.ends_with("my-schema-v1.proto") ||
schema.ends_with("my-schema-v2.proto")) {
Ok(())
} else {
Err(format!("incompatible schema: {}", schema))
}
};
assert_eq!(
Ok(()),
SchemaMatcher::<MyMessage>::try_match_schema(
&my_matcher,
"messages/my-message/my-schema-v2.proto"
)
);
assert_eq!(
Err("incompatible schema: messages/my-message/my-schema-v3.proto".to_owned()),
SchemaMatcher::<MyMessage>::try_match_schema(
&my_matcher,
"messages/my-message/my-schema-v3.proto"
)
);
Associated Types
The error returned when a given schema does not match the message type
Required methods
fn try_match_schema(&self, schema: &str) -> Result<(), Self::InvalidSchemaError>
fn try_match_schema(&self, schema: &str) -> Result<(), Self::InvalidSchemaError>
Check whether messages with the given schema are valid for deserializing into the trait’s generic message type.
Returns an error if the schema does not match