Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support no_std on windows #49

Open
Plecra opened this issue Jul 4, 2021 · 1 comment
Open

Support no_std on windows #49

Plecra opened this issue Jul 4, 2021 · 1 comment

Comments

@Plecra
Copy link

Plecra commented Jul 4, 2021

atty/src/lib.rs

Line 131 in 7b5df17

let mut name_info_bytes = vec![0u8; size + MAX_PATH * mem::size_of::<WCHAR>()];

By replacing this vector with an array, we can remove the std dependency. The allocation is only 524 bytes long, and it wouldn't be unreasonable to allocate it on the stack (Rust's default stack size is 2MiB, giving us plenty of room).

We'd also need to remove the utf16 conversion that allocates to a string here:

atty/src/lib.rs

Line 146 in 7b5df17

let name = String::from_utf16_lossy(s);

One solution would simply be to write s.contains(&[b'-' as u16, 'p' as _, 't' as _, 'y' as _]), but there's also https://docs.rs/utf16_lit which makes this more readable

@BurntSushi
Copy link
Contributor

@Plecra Could you say what the use case is for no_std support on Windows? Where would it allow the use of this crate that is otherwise impossible today? Making the substring check even more obscure, for example, seems non-ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants