pub trait ReadableWriteableDataSchema<DS, AS, OS, Extended>: BuildableDataSchema<DS, AS, OS, Extended> {
type ReadOnly: BuildableDataSchema<DS, AS, OS, Extended>;
type WriteOnly: BuildableDataSchema<DS, AS, OS, Extended>;
// Required methods
fn read_only(self) -> Self::ReadOnly;
fn write_only(self) -> Self::WriteOnly;
}Expand description
An interface to specialize a read-only/write-only version of a
DataSchema.
Some specializations of DataSchema can be set as read-only or write-only. When
implemented, this allows a safe abstraction over these situations, avoiding conflicting states
a compile-time.
§Notes
- This trait should not be implemented directly, even if it is not sealed.
Required Associated Types§
Sourcetype ReadOnly: BuildableDataSchema<DS, AS, OS, Extended>
type ReadOnly: BuildableDataSchema<DS, AS, OS, Extended>
The read-only variant of the data schema builder.
Sourcetype WriteOnly: BuildableDataSchema<DS, AS, OS, Extended>
type WriteOnly: BuildableDataSchema<DS, AS, OS, Extended>
The write-only variant of the data schema builder.
Required Methods§
Sourcefn read_only(self) -> Self::ReadOnly
fn read_only(self) -> Self::ReadOnly
Creates a read-only variant of the data schema builder.
§Examples
let thing = Thing::builder("Thing name")
.finish_extend()
.schema_definition("test", |b| {
b.finish_extend()
.integer()
.minimum(5)
.read_only()
.maximum(10)
})
.build()
.unwrap();
assert_eq!(
serde_json::to_value(thing).unwrap(),
json!({
"@context": "https://www.w3.org/2022/wot/td/v1.1",
"title": "Thing name",
"schemaDefinitions": {
"test": {
"type": "integer",
"readOnly": true,
"writeOnly": false,
"minimum": 5,
"maximum": 10,
}
},
"security": [],
"securityDefinitions": {},
})
);The example using write_only is analogous. However, it is not possible to call both
read_only and write_only on the same data schema building chain:
let thing = Thing::builder("Thing name")
.finish_extend()
.schema_definition("test", |b| {
b.finish_extend().integer().read_only().write_only()
})
.build()
.unwrap();Sourcefn write_only(self) -> Self::WriteOnly
fn write_only(self) -> Self::WriteOnly
Creates a write-only variant of the data schema builder.
See read_only for examples.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.