psp_net/traits/io.rs
1pub trait OptionType {
2 type Options<'b>: ?Sized;
3}
4
5/// Types implementing this trait support a Open semantics.
6pub trait Open<'a, 'b>: ErrorType + OptionType {
7 type Return;
8
9 /// Open a resource, using options for configuration.
10 ///
11 /// # Arguments
12 /// - `options`: The options to use to configure the TLS connection
13 ///
14 /// # Errors
15 /// This function can return an error if the resource could not be opened.
16 ///
17 /// # Notes
18 /// See [`TlsSocketOptions`](crate::types::TlsSocketOptions) for more information
19 /// on the options you can pass.
20 fn open(self, options: &'b Self::Options<'b>) -> Result<Self::Return, Self::Error>
21 where
22 Self: Sized,
23 'b: 'a;
24}
25
26/// Types implementing this trait support a simplified socket use.
27///
28/// [`EasySocket`] types support sockets with an Open/Close, Read/Write semantics.
29///
30/// As usual in Rust, no `close` method is needed, as dropping an object should
31/// already close the resources.
32///
33/// `EasySockets` methods to be used are [`open`](Open::open), [`read`](embedded_io::Read::read),
34/// [`write`](embedded_io::Write::write) and [`flush`](embedded_io::Write::flush). Likely, a `new` method is
35/// needed befor opening the socket, but this depends on the implementation.
36///
37/// # Notes
38/// [`EasySocket`] types should implement in their [`drop`] method the steps required
39/// to close the acquired resources.
40pub trait EasySocket: Write + Read {}
41
42// re-exports
43pub trait Write = embedded_io::Write;
44pub trait Read = embedded_io::Read;
45pub trait ErrorType = embedded_io::ErrorType;