Coder Social home page Coder Social logo

rust-libc-print's Introduction

no_std libc print/println/eprint/eprintln/dbg

Build Status docs.rs crates.io

Implements println!, eprintln! and dbg! on the libc crate without requiring the use of an allocator.

Allows you to use these macros in a #![no_std] context, or in a situation where the traditional Rust streams might not be available (ie: at process shutdown time).

By default this crate provides libc_-prefixed macros, but also allows consumers to import macros with the same name as the stdlib printing macros via the std_name module.

Usage

Exactly as you'd use println!, eprintln! and dbg!.

#![no_std]

// Use the default `libc_`-prefixed macros:
libc_println!("Hello {}!", "stdout");
libc_eprintln!("Hello {}!", "stderr");
let a = 2;
let b = libc_dbg!(a * 2) + 1;
assert_eq!(b, 5);

Or you can import aliases to std names:

use libc_print::std_name::{println, eprintln, dbg};

println!("Hello {}!", "stdout");
eprintln!("Hello {}!", "stderr");
let a = 2;
let b = dbg!(a * 2) + 1;
assert_eq!(b, 5);

rust-libc-print's People

Contributors

brandonweeks avatar daniel5151 avatar dependabot-preview[bot] avatar dependabot[bot] avatar jturner314 avatar mmastrac avatar sabrinajewson avatar stevelauc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rust-libc-print's Issues

Suggestion for flushing stdout?

Hello, thank you for sharing this crate. ๐Ÿ‘
println! macros in std don't immediately flush stdout, and therefore may need something like std::io::stdout().flush().expect("error while flushing stdin"); to ensure immediate printing behavior.

Is there a recommended way to flush stdout while using this crate in #![no_std]?
Thank you ๐Ÿ˜„

add libc_dbg! macro

Hi, thanks for the crate, really useful.

I've mainly been using this crate for debugging in a #![no_std] context. I think t would be useful to have the dbg! macro available too.

Unusable without std

Whenever I add this crate to Cargo.toml linking fails:

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/rafalh/.rustup/toolchains/nightly-2019-07-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/mnt/storage/Rust/fatfs-test/target/debug/deps/fatfs_test-8da1ad26e70363f0.1eyj4q01wj34higz.rcgu.o" "/mnt/storage/Rust/fatfs-test/target/debug/deps/fatfs_test-8da1ad26e70363f0.2s5qo53vqjbghd43.rcgu.o" "-o" "/mnt/storage/Rust/fatfs-test/target/debug/deps/fatfs_test-8da1ad26e70363f0" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/mnt/storage/Rust/fatfs-test/target/debug/deps" "-L" "/home/rafalh/.rustup/toolchains/nightly-2019-07-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/mnt/storage/Rust/fatfs-test/target/debug/deps/liblibc-8c525ceb5ef9877e.rlib" "/home/rafalh/.rustup/toolchains/nightly-2019-07-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-745a89ce61515994.rlib" "/home/rafalh/.rustup/toolchains/nightly-2019-07-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-18d07502766ba5a6.rlib" "/home/rafalh/.rustup/toolchains/nightly-2019-07-01-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-a5d932270c582439.rlib" "-Wl,-Bdynamic" "-lutil" "-lutil"
  = note: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
          (.text+0x12): undefined reference to `__libc_csu_fini'
          (.text+0x19): undefined reference to `__libc_csu_init'
          (.text+0x26): undefined reference to `__libc_start_main'
          /mnt/storage/Rust/fatfs-test/target/debug/deps/fatfs_test-8da1ad26e70363f0.1eyj4q01wj34higz.rcgu.o: In function `main':
          /mnt/storage/Rust/fatfs-test/src/main.rs:30: undefined reference to `printf'
          collect2: error: ld returned 1 exit status

I'm pretty sure it's caused by missing default-features = False flag for libc dependency in this crate.

libc::write not found in `libc`

Thanks for the great library.
I am trying it with cargo build --target thumbv8m.main-none-eabihf

I am having these two compilation errors.

error[E0425]: cannot find function `write` in crate `libc`
  --> .../.cargo/registry/src/github.com-1ecc6299db9ec823/libc-print-0.1.17/src/lib.rs:70:15
   |
70 |         libc::write(
   |               ^^^^^ not found in `libc`
   |
help: consider importing one of these items
   |
17 | use core::fmt::write;
   |
17 | use core::ptr::write;
   |

error[E0412]: cannot find type `size_t` in crate `libc`
  --> .../.cargo/registry/src/github.com-1ecc6299db9ec823/libc-print-0.1.17/src/lib.rs:73:32
   |
73 |             msg.len() as libc::size_t,
   |                                ^^^^^^ not found in `libc`

Any ideas?

when i use it time , it tell link.exe error

linking with link.exe failed: exit code: 1120
but i add .cargo/config.toml
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-arg=-nostartfiles"]

[target.'cfg(target_os = "windows")']
rustflags = ["-C", "link-args=/ENTRY:_start /SUBSYSTEM:console"]

[target.'cfg(target_os = "macos")']
rustflags = ["-C", "link-args=-e __start -static -nostartfiles"]

so i want konw why?

"attributes on expressions are experimental" when not used as a statement

Offending excerpt from my code:

use libc_print::std_name::*;

// ...

foo().unwrap_or_else(|err| eprintln!("error: {:?}", err));

My best guess is that there needs to be some added block level and/or semicolon to get the macro call to compile in all cases without needing #![feature(stmt_expr_attributes)].

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.