forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 465
Add Rust int param types #87
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4021d94
Add ModuleParam trait and new int params
adamrk 0fbeb9f
Add usize param to examples
adamrk 901cd01
Add NO_ARG and bool ops
adamrk 8c8b479
Add docs
adamrk 923540b
rustfmt
adamrk edf5833
Improve docs
adamrk fce463d
clean up export symbol regex
adamrk 5d8e7af
remove doc.rust-lang.org links
adamrk 41325ef
fix PAGE_SIZE doc link
adamrk 3ec22aa
add link to PAGE_SHIFT in C
adamrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
|
||
//! Struct for writing to a pre-allocated buffer with the [`write!`] macro. | ||
|
||
use core::fmt; | ||
|
||
/// A pre-allocated buffer that implements [`core::fmt::Write`]. | ||
/// | ||
/// Consequtive writes will append to what has already been written. | ||
/// Writes that don't fit in the buffer will fail. | ||
pub struct Buffer<'a> { | ||
slice: &'a mut [u8], | ||
pos: usize, | ||
} | ||
|
||
impl<'a> Buffer<'a> { | ||
/// Create a new buffer from an existing array. | ||
pub fn new(slice: &'a mut [u8]) -> Self { | ||
Buffer { slice, pos: 0 } | ||
} | ||
|
||
/// Number of bytes that have already been written to the buffer. | ||
/// This will always be less than the length of the original array. | ||
pub fn bytes_written(&self) -> usize { | ||
self.pos | ||
} | ||
} | ||
|
||
impl<'a> fmt::Write for Buffer<'a> { | ||
fn write_str(&mut self, s: &str) -> fmt::Result { | ||
if s.len() > self.slice.len() - self.pos { | ||
Err(fmt::Error) | ||
} else { | ||
self.slice[self.pos..self.pos + s.len()].copy_from_slice(s.as_bytes()); | ||
self.pos += s.len(); | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.