1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-08-08 08:22:52 +02:00

ensure to have explicit main functions in typestate pattern

This commit is contained in:
Glen De Cauwsemaecker
2025-07-16 16:01:46 +02:00
parent c69bffcb74
commit 2ac209c9a9
2 changed files with 16 additions and 14 deletions

View File

@ -32,12 +32,14 @@ impl SerializeStruct {
} }
} }
let ser = Serializer::default() fn main() {
let ser = Serializer::default()
.serialize_struct("User") .serialize_struct("User")
.serialize_field("id", "42") .serialize_field("id", "42")
.serialize_field("name", "Alice") .serialize_field("name", "Alice")
.finish_struct(); .finish_struct();
println!("{}", ser.output); println!("{}", ser.output);
}
``` ```
<details> <details>

View File

@ -5,7 +5,6 @@ shared logic across state variants, while still encoding state transitions in
the type system. the type system.
```rust ```rust
# fn main() -> std::io::Result<()> {
#[non_exhaustive] #[non_exhaustive]
struct Insecure; struct Insecure;
struct Secure { struct Secure {
@ -85,13 +84,14 @@ impl<T: Transport> ConnectionBuilder<Ready<T>> {
} }
} }
let _conn = Connection::new("db.local") fn main() -> std::io::Result<()> {
let _conn = Connection::new("db.local")
.secure() .secure()
.client_certificate(vec![1, 2, 3]) .client_certificate(vec![1, 2, 3])
.timeout(10) .timeout(10)
.connect()?; .connect()?;
Ok(()) Ok(())
# } }
``` ```
<details> <details>