File tree 1 file changed +31
-0
lines changed
1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1161,7 +1161,38 @@ pub trait IsTerminal: crate::sealed::Sealed {
1161
1161
/// starting with `msys-` or `cygwin-` and ending in `-pty` will be considered terminals.
1162
1162
/// Note that this [may change in the future][changes].
1163
1163
///
1164
+ /// # Examples
1165
+ ///
1166
+ /// An example of a type for which `IsTerminal` is implemented is [`Stdin`]:
1167
+ ///
1168
+ /// ```no_run
1169
+ /// use std::io::{self, IsTerminal};
1170
+ ///
1171
+ /// fn main() -> io::Result<()> {
1172
+ /// let stdin = io::stdin();
1173
+ ///
1174
+ /// if stdin.is_terminal() {
1175
+ /// panic!("Expected input to be piped to the process");
1176
+ /// }
1177
+ ///
1178
+ /// let mut name = String::new();
1179
+ /// let _ = stdin.read_line(&mut name)?;
1180
+ ///
1181
+ /// println!("Hello {name}");
1182
+ ///
1183
+ /// Ok(())
1184
+ /// }
1185
+ /// ```
1186
+ ///
1187
+ /// The example can be run in two ways:
1188
+ ///
1189
+ /// - If you run this example by piping some text to it, e.g. `printf foo | path/to/executable`
1190
+ /// it will print: `Hello foo`.
1191
+ /// - If you instead run the example interactively by running the executable directly, it will
1192
+ /// panic with the message "Expected input to be piped to the process".
1193
+ ///
1164
1194
/// [changes]: io#platform-specific-behavior
1195
+ /// [`Stdin`]: crate::io::Stdin
1165
1196
#[ stable( feature = "is_terminal" , since = "1.70.0" ) ]
1166
1197
fn is_terminal ( & self ) -> bool ;
1167
1198
}
You can’t perform that action at this time.
0 commit comments