-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support no_std w\ enabled-by-default "use_std" feature
- Changes all references to libcore features from ::std to ::core - Feature gates anything dependent on std::io on the "use_std" feature - Obtains Box, String, and Vec from liballoc in no_std environments - Vendors a tiny bit of std::io::cursor for use in no_std environments
- Loading branch information
Showing
15 changed files
with
153 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,54 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
/// A `Cursor` wraps another type and provides it with a | ||
/// [`Seek`] implementation. | ||
/// | ||
/// `Cursor`s are typically used with in-memory buffers to allow them to | ||
/// implement [`Read`] and/or [`Write`], allowing these buffers to be used | ||
/// anywhere you might use a reader or writer that does actual I/O. | ||
/// | ||
/// The standard library implements some I/O traits on various types which | ||
/// are commonly used as a buffer, like `Cursor<`[`Vec`]`<u8>>` and | ||
/// `Cursor<`[`&[u8]`][bytes]`>`. | ||
#[derive(Clone, Debug)] | ||
pub struct Cursor<T> { | ||
inner: T, | ||
pos: u64, | ||
} | ||
|
||
impl<T> Cursor<T> { | ||
/// Creates a new cursor wrapping the provided underlying I/O object. | ||
/// | ||
/// Cursor initial position is `0` even if underlying object (e. | ||
/// g. `Vec`) is not empty. So writing to cursor starts with | ||
/// overwriting `Vec` content, not with appending to it. | ||
pub fn new(inner: T) -> Cursor<T> { | ||
Cursor { pos: 0, inner: inner } | ||
} | ||
|
||
/// Consumes this cursor, returning the underlying value. | ||
pub fn into_inner(self) -> T { self.inner } | ||
|
||
/// Gets a reference to the underlying value in this cursor. | ||
pub fn get_ref(&self) -> &T { &self.inner } | ||
|
||
/// Gets a mutable reference to the underlying value in this cursor. | ||
/// | ||
/// Care should be taken to avoid modifying the internal I/O state of the | ||
/// underlying value as it may corrupt this cursor's position. | ||
pub fn get_mut(&mut self) -> &mut T { &mut self.inner } | ||
|
||
/// Returns the current position of this cursor. | ||
pub fn position(&self) -> u64 { self.pos } | ||
|
||
/// Sets the position of this cursor. | ||
pub fn set_position(&mut self, pos: u64) { self.pos = pos; } | ||
} |
This file contains 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 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 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 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 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 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.