Rust Getting started with Rust Console output without macros

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

// use Write trait that contains write() function
use std::io::Write;

fn main() {
    std::io::stdout().write(b"Hello, world!\n").unwrap();
}
  • The std::io::Write trait is designed for objects which accept byte streams. In this case, a handle to standard output is acquired with std::io::stdout().

  • Write::write() accepts a byte slice (&[u8]), which is created with a byte-string literal (b"<string>"). Write::write() returns a Result<usize, IoError>, which contains either the number of bytes written (on success) or an error value (on failure).

  • The call to Result::unwrap() indicates that the call is expected to succeed (Result<usize, IoError> -> usize), and the value is discarded.



Got any Rust Question?