2525//! ```
2626//! # use self::nix::sys::termios::SpecialCharacterIndices::VEOF;
2727//! # 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 () };
2929//! termios.control_chars[VEOF as usize] = _POSIX_VDISABLE;
3030//! ```
3131//!
3838//!
3939//! ```
4040//! # use self::nix::sys::termios::{ControlFlags, Termios};
41- //! # let mut termios = unsafe { Termios::default_uninit () };
41+ //! # let mut termios: Termios = unsafe { std::mem::zeroed () };
4242//! termios.control_flags & ControlFlags::CSIZE == ControlFlags::CS5;
4343//! termios.control_flags |= ControlFlags::CS5;
4444//! ```
6161//! platforms:
6262//!
6363//! ```rust
64- //! # #[macro_use] extern crate nix;
6564//! # use nix::sys::termios::{BaudRate, cfsetispeed, cfsetospeed, cfsetspeed, Termios};
6665//! # fn main() {
67- //! # let mut t = unsafe { Termios::default_uninit () };
66+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
6867//! cfsetispeed(&mut t, BaudRate::B9600);
6968//! cfsetospeed(&mut t, BaudRate::B9600);
7069//! cfsetspeed(&mut t, BaudRate::B9600);
7675//! ```rust
7776//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetispeed, cfsetspeed, Termios};
7877//! # fn main() {
79- //! # let mut t = unsafe { Termios::default_uninit () };
78+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
8079//! # cfsetspeed(&mut t, BaudRate::B9600);
8180//! let speed = cfgetispeed(&t);
8281//! assert_eq!(speed, cfgetospeed(&t));
9493 doc = " ```rust" ) ]
9594//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
9695//! # fn main() {
97- //! # let mut t = unsafe { Termios::default_uninit () };
96+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
9897//! # cfsetspeed(&mut t, BaudRate::B9600);
9998//! assert_eq!(cfgetispeed(&t), BaudRate::B9600);
10099//! assert_eq!(cfgetospeed(&t), BaudRate::B9600);
111110 doc = " ```rust,ignore" ) ]
112111//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfgetospeed, cfsetspeed, Termios};
113112//! # fn main() {
114- //! # let mut t = unsafe { Termios::default_uninit () };
113+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
115114//! # cfsetspeed(&mut t, 9600u32);
116115//! assert_eq!(cfgetispeed(&t), 9600u32);
117116//! assert_eq!(cfgetospeed(&t), 9600u32);
128127 doc = " ```rust,ignore" ) ]
129128//! # use nix::sys::termios::{BaudRate, cfgetispeed, cfsetspeed, Termios};
130129//! # fn main() {
131- //! # let mut t = unsafe { Termios::default_uninit () };
130+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
132131//! # cfsetspeed(&mut t, 9600u32);
133132//! assert_eq!(cfgetispeed(&t), BaudRate::B9600.into());
134133//! assert_eq!(u32::from(BaudRate::B9600), 9600u32);
146145 doc = " ```rust,ignore" ) ]
147146//! # use nix::sys::termios::{cfsetispeed, cfsetospeed, cfsetspeed, Termios};
148147//! # fn main() {
149- //! # let mut t = unsafe { Termios::default_uninit () };
148+ //! # let mut t: Termios = unsafe { std::mem::zeroed () };
150149//! cfsetispeed(&mut t, 9600u32);
151150//! cfsetospeed(&mut t, 9600u32);
152151//! cfsetspeed(&mut t, 9600u32);
@@ -186,22 +185,9 @@ pub struct Termios {
186185impl Termios {
187186 /// Exposes an immutable reference to the underlying `libc::termios` data structure.
188187 ///
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 > {
205191 {
206192 let mut termios = self . inner . borrow_mut ( ) ;
207193 termios. c_iflag = self . input_flags . bits ( ) ;
@@ -215,12 +201,11 @@ impl Termios {
215201
216202 /// Exposes the inner `libc::termios` datastore within `Termios`.
217203 ///
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 {
224209 {
225210 let mut termios = self . inner . borrow_mut ( ) ;
226211 termios. c_iflag = self . input_flags . bits ( ) ;
@@ -232,26 +217,8 @@ impl Termios {
232217 self . inner . as_ptr ( )
233218 }
234219
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-
252220 /// 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 ) {
255222 let termios = * self . inner . borrow_mut ( ) ;
256223 self . input_flags = InputFlags :: from_bits_truncate ( termios. c_iflag ) ;
257224 self . output_flags = OutputFlags :: from_bits_truncate ( termios. c_oflag ) ;
0 commit comments