25
25
//! ```
26
26
//! # use self::nix::sys::termios::SpecialCharacterIndices::VEOF;
27
27
//! # use self::nix::sys::termios::{_POSIX_VDISABLE, Termios};
28
- //! # let mut termios = unsafe { Termios::default_uninit () };
28
+ //! # let mut termios: Termios = unsafe { std::mem::zeroed () };
29
29
//! termios.control_chars[VEOF as usize] = _POSIX_VDISABLE;
30
30
//! ```
31
31
//!
38
38
//!
39
39
//! ```
40
40
//! # use self::nix::sys::termios::{ControlFlags, Termios};
41
- //! # let mut termios = unsafe { Termios::default_uninit () };
41
+ //! # let mut termios: Termios = unsafe { std::mem::zeroed () };
42
42
//! termios.control_flags & ControlFlags::CSIZE == ControlFlags::CS5;
43
43
//! termios.control_flags |= ControlFlags::CS5;
44
44
//! ```
61
61
//! platforms:
62
62
//!
63
63
//! ```rust
64
- //! # #[macro_use] extern crate nix;
65
64
//! # use nix::sys::termios::{BaudRate, cfsetispeed, cfsetospeed, cfsetspeed, Termios};
66
65
//! # fn main() {
67
- //! # let mut t = unsafe { Termios::default_uninit () };
66
+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
68
67
//! cfsetispeed(&mut t, BaudRate::B9600);
69
68
//! cfsetospeed(&mut t, BaudRate::B9600);
70
69
//! cfsetspeed(&mut t, BaudRate::B9600);
76
75
//! ```rust
77
76
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetispeed, cfsetspeed, Termios};
78
77
//! # fn main() {
79
- //! # let mut t = unsafe { Termios::default_uninit () };
78
+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
80
79
//! # cfsetspeed(&mut t, BaudRate::B9600);
81
80
//! let speed = cfgetispeed(&t);
82
81
//! assert_eq!(speed, cfgetospeed(&t));
94
93
doc = " ```rust" ) ]
95
94
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
96
95
//! # fn main() {
97
- //! # let mut t = unsafe { Termios::default_uninit () };
96
+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
98
97
//! # cfsetspeed(&mut t, BaudRate::B9600);
99
98
//! assert_eq!(cfgetispeed(&t), BaudRate::B9600);
100
99
//! assert_eq!(cfgetospeed(&t), BaudRate::B9600);
111
110
doc = " ```rust,ignore" ) ]
112
111
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
113
112
//! # fn main() {
114
- //! # let mut t = unsafe { Termios::default_uninit () };
113
+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
115
114
//! # cfsetspeed(&mut t, 9600u32);
116
115
//! assert_eq!(cfgetispeed(&t), 9600u32);
117
116
//! assert_eq!(cfgetospeed(&t), 9600u32);
128
127
doc = " ```rust,ignore" ) ]
129
128
//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfsetspeed, Termios};
130
129
//! # fn main() {
131
- //! # let mut t = unsafe { Termios::default_uninit () };
130
+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
132
131
//! # cfsetspeed(&mut t, 9600u32);
133
132
//! assert_eq!(cfgetispeed(&t), BaudRate::B9600.into());
134
133
//! assert_eq!(u32::from(BaudRate::B9600), 9600u32);
146
145
doc = " ```rust,ignore" ) ]
147
146
//! # use nix::sys::termios::{cfsetispeed, cfsetospeed, cfsetspeed, Termios};
148
147
//! # fn main() {
149
- //! # let mut t = unsafe { Termios::default_uninit () };
148
+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
150
149
//! cfsetispeed(&mut t, 9600u32);
151
150
//! cfsetospeed(&mut t, 9600u32);
152
151
//! cfsetspeed(&mut t, 9600u32);
@@ -186,22 +185,9 @@ pub struct Termios {
186
185
impl Termios {
187
186
/// Exposes an immutable reference to the underlying `libc::termios` data structure.
188
187
///
189
- /// This can be used for interfacing with other FFI functions like:
190
- ///
191
- /// ```rust
192
- /// # fn main() {
193
- /// # use nix::sys::termios::Termios;
194
- /// # let mut termios = unsafe { Termios::default_uninit() };
195
- /// let inner_termios = termios.get_libc_termios();
196
- /// unsafe { libc::cfgetispeed(&*inner_termios) };
197
- /// # }
198
- /// ```
199
- ///
200
- /// There is no public API exposed for functions that modify the underlying `libc::termios`
201
- /// data because it requires additional work to maintain type safety.
202
- // FIXME: Switch this over to use pub(crate)
203
- #[ doc( hidden) ]
204
- pub fn get_libc_termios ( & self ) -> Ref < libc:: termios > {
188
+ /// This is not part of `nix`'s public API because it requires additional work to maintain type
189
+ /// safety.
190
+ pub ( crate ) fn get_libc_termios ( & self ) -> Ref < libc:: termios > {
205
191
{
206
192
let mut termios = self . inner . borrow_mut ( ) ;
207
193
termios. c_iflag = self . input_flags . bits ( ) ;
@@ -215,12 +201,11 @@ impl Termios {
215
201
216
202
/// Exposes the inner `libc::termios` datastore within `Termios`.
217
203
///
218
- /// This is unsafe because if this is used to modify the inner libc::termios struct, it will not
219
- /// automatically update the safe wrapper type around it. Therefore we disable docs to
220
- /// effectively limit its use to nix internals. In this case it should also be paired with a
221
- /// call to `update_wrapper()` so that the wrapper-type and internal representation stay
222
- /// consistent.
223
- unsafe fn get_libc_termios_mut ( & mut self ) -> * mut libc:: termios {
204
+ /// This is unsafe because if this is used to modify the inner `libc::termios` struct, it will
205
+ /// not automatically update the safe wrapper type around it. In this case it should also be
206
+ /// paired with a call to `update_wrapper()` so that the wrapper-type and internal
207
+ /// representation stay consistent.
208
+ pub ( crate ) unsafe fn get_libc_termios_mut ( & mut self ) -> * mut libc:: termios {
224
209
{
225
210
let mut termios = self . inner . borrow_mut ( ) ;
226
211
termios. c_iflag = self . input_flags . bits ( ) ;
@@ -232,26 +217,8 @@ impl Termios {
232
217
self . inner . as_ptr ( )
233
218
}
234
219
235
- /// Allows for easily creating new `Termios` structs that will be overwritten with real data.
236
- ///
237
- /// This should only be used when the inner libc::termios struct will be overwritten before it's
238
- /// read.
239
- // FIXME: Switch this over to use pub(crate)
240
- #[ doc( hidden) ]
241
- pub unsafe fn default_uninit ( ) -> Self {
242
- Termios {
243
- inner : RefCell :: new ( mem:: zeroed ( ) ) ,
244
- input_flags : InputFlags :: empty ( ) ,
245
- output_flags : OutputFlags :: empty ( ) ,
246
- control_flags : ControlFlags :: empty ( ) ,
247
- local_flags : LocalFlags :: empty ( ) ,
248
- control_chars : [ 0 as libc:: cc_t ; NCCS ] ,
249
- }
250
- }
251
-
252
220
/// Updates the wrapper values from the internal `libc::termios` data structure.
253
- #[ doc( hidden) ]
254
- pub fn update_wrapper ( & mut self ) {
221
+ pub ( crate ) fn update_wrapper ( & mut self ) {
255
222
let termios = * self . inner . borrow_mut ( ) ;
256
223
self . input_flags = InputFlags :: from_bits_truncate ( termios. c_iflag ) ;
257
224
self . output_flags = OutputFlags :: from_bits_truncate ( termios. c_oflag ) ;
0 commit comments