about summary refs log tree commit diff
path: root/src/libstd/ffi
AgeCommit message (Collapse)AuthorLines
2016-01-19Improve CStr::from_ptr example in docsAndrea Bedini-2/+1
Documentation of `CStr::from_ptr` suggests using `str::from_utf8(slice.to_bytes()).unwrap()` to obtain a `&str` but `CStr` has `CStr::to_str` that does exactly that.
2016-01-16std: Stabilize APIs for the 1.7 releaseAlex Crichton-11/+21
This commit stabilizes and deprecates the FCP (final comment period) APIs for the upcoming 1.7 beta release. The specific APIs which changed were: Stabilized * `Path::strip_prefix` (renamed from `relative_from`) * `path::StripPrefixError` (new error type returned from `strip_prefix`) * `Ipv4Addr::is_loopback` * `Ipv4Addr::is_private` * `Ipv4Addr::is_link_local` * `Ipv4Addr::is_multicast` * `Ipv4Addr::is_broadcast` * `Ipv4Addr::is_documentation` * `Ipv6Addr::is_unspecified` * `Ipv6Addr::is_loopback` * `Ipv6Addr::is_unique_local` * `Ipv6Addr::is_multicast` * `Vec::as_slice` * `Vec::as_mut_slice` * `String::as_str` * `String::as_mut_str` * `<[T]>::clone_from_slice` - the `usize` return value is removed * `<[T]>::sort_by_key` * `i32::checked_rem` (and other signed types) * `i32::checked_neg` (and other signed types) * `i32::checked_shl` (and other signed types) * `i32::checked_shr` (and other signed types) * `i32::saturating_mul` (and other signed types) * `i32::overflowing_add` (and other signed types) * `i32::overflowing_sub` (and other signed types) * `i32::overflowing_mul` (and other signed types) * `i32::overflowing_div` (and other signed types) * `i32::overflowing_rem` (and other signed types) * `i32::overflowing_neg` (and other signed types) * `i32::overflowing_shl` (and other signed types) * `i32::overflowing_shr` (and other signed types) * `u32::checked_rem` (and other unsigned types) * `u32::checked_neg` (and other unsigned types) * `u32::checked_shl` (and other unsigned types) * `u32::saturating_mul` (and other unsigned types) * `u32::overflowing_add` (and other unsigned types) * `u32::overflowing_sub` (and other unsigned types) * `u32::overflowing_mul` (and other unsigned types) * `u32::overflowing_div` (and other unsigned types) * `u32::overflowing_rem` (and other unsigned types) * `u32::overflowing_neg` (and other unsigned types) * `u32::overflowing_shl` (and other unsigned types) * `u32::overflowing_shr` (and other unsigned types) * `ffi::IntoStringError` * `CString::into_string` * `CString::into_bytes` * `CString::into_bytes_with_nul` * `From<CString> for Vec<u8>` * `From<CString> for Vec<u8>` * `IntoStringError::into_cstring` * `IntoStringError::utf8_error` * `Error for IntoStringError` Deprecated * `Path::relative_from` - renamed to `strip_prefix` * `Path::prefix` - use `components().next()` instead * `os::unix::fs` constants - moved to the `libc` crate * `fmt::{radix, Radix, RadixFmt}` - not used enough to stabilize * `IntoCow` - conflicts with `Into` and may come back later * `i32::{BITS, BYTES}` (and other integers) - not pulling their weight * `DebugTuple::formatter` - will be removed * `sync::Semaphore` - not used enough and confused with system semaphores Closes #23284 cc #27709 (still lots more methods though) Closes #27712 Closes #27722 Closes #27728 Closes #27735 Closes #27729 Closes #27755 Closes #27782 Closes #27798
2016-01-07Move os_str docs to OsString in order to be visible in HTML (fixes #30743)Georg Brandl-23/+17
2015-12-31CStr impl stabilityarcnmx-4/+4
2015-12-31impl From<&CStr> for CStringarcnmx-7/+7
2015-12-29AsRef and related conversions for CStringarcnmx-2/+33
2015-12-18Use memchr in libstd where possible, closes #30076Florian Hahn-1/+2
2015-12-10std: Remove deprecated functionality from 1.5Alex Crichton-27/+0
This is a standard "clean out libstd" commit which removes all 1.5-and-before deprecated functionality as it's now all been deprecated for at least one entire cycle.
2015-12-05std: Stabilize APIs for the 1.6 releaseAlex Crichton-0/+7
This commit is the standard API stabilization commit for the 1.6 release cycle. The list of issues and APIs below have all been through their cycle-long FCP and the libs team decisions are listed below Stabilized APIs * `Read::read_exact` * `ErrorKind::UnexpectedEof` (renamed from `UnexpectedEOF`) * libcore -- this was a bit of a nuanced stabilization, the crate itself is now marked as `#[stable]` and the methods appearing via traits for primitives like `char` and `str` are now also marked as stable. Note that the extension traits themeselves are marked as unstable as they're imported via the prelude. The `try!` macro was also moved from the standard library into libcore to have the same interface. Otherwise the functions all have copied stability from the standard library now. * The `#![no_std]` attribute * `fs::DirBuilder` * `fs::DirBuilder::new` * `fs::DirBuilder::recursive` * `fs::DirBuilder::create` * `os::unix::fs::DirBuilderExt` * `os::unix::fs::DirBuilderExt::mode` * `vec::Drain` * `vec::Vec::drain` * `string::Drain` * `string::String::drain` * `vec_deque::Drain` * `vec_deque::VecDeque::drain` * `collections::hash_map::Drain` * `collections::hash_map::HashMap::drain` * `collections::hash_set::Drain` * `collections::hash_set::HashSet::drain` * `collections::binary_heap::Drain` * `collections::binary_heap::BinaryHeap::drain` * `Vec::extend_from_slice` (renamed from `push_all`) * `Mutex::get_mut` * `Mutex::into_inner` * `RwLock::get_mut` * `RwLock::into_inner` * `Iterator::min_by_key` (renamed from `min_by`) * `Iterator::max_by_key` (renamed from `max_by`) Deprecated APIs * `ErrorKind::UnexpectedEOF` (renamed to `UnexpectedEof`) * `OsString::from_bytes` * `OsStr::to_cstring` * `OsStr::to_bytes` * `fs::walk_dir` and `fs::WalkDir` * `path::Components::peek` * `slice::bytes::MutableByteVector` * `slice::bytes::copy_memory` * `Vec::push_all` (renamed to `extend_from_slice`) * `Duration::span` * `IpAddr` * `SocketAddr::ip` * `Read::tee` * `io::Tee` * `Write::broadcast` * `io::Broadcast` * `Iterator::min_by` (renamed to `min_by_key`) * `Iterator::max_by` (renamed to `max_by_key`) * `net::lookup_addr` New APIs (still unstable) * `<[T]>::sort_by_key` (added to mirror `min_by_key`) Closes #27585 Closes #27704 Closes #27707 Closes #27710 Closes #27711 Closes #27727 Closes #27740 Closes #27744 Closes #27799 Closes #27801 cc #27801 (doesn't close as `Chars` is still unstable) Closes #28968
2015-11-20Rename #[deprecated] to #[rustc_deprecated]Vadim Petrochenkov-2/+2
2015-11-11Cleaner c_char cfg logicarcnmx-5/+4
2015-11-11Prefer raw::c_char or libc::c_char and fix armarcnmx-37/+30
2015-10-19Owned conversions for CStringarcnmx-2/+72
2015-10-01replaced *_ptr with *_raw methods in docsCristian Kubis-3/+3
2015-10-01doc: fixed swapped docs for from_ptr and from_rawCristian Kubis-4/+4
2015-09-14Auto merge of #28256 - petrochenkov:conv, r=alexcrichtonbors-11/+14
This patch transforms functions of the form ``` fn f<Generic: AsRef<Concrete>>(arg: Generic) { let arg: &Concrete = arg.as_ref(); // Code using arg } ``` to the next form: ``` #[inline] fn f<Generic: AsRef<Concrete>>(arg: Generic) { fn f_inner(arg: &Concrete) { // Code using arg } f_inner(arg.as_ref()); } ``` Therefore, most of the code is concrete and not duplicated during monomorphisation (unless inlined) and only the tiny bit of conversion code is duplicated. This method was mentioned by @aturon in the Conversion Traits RFC (https://github.com/rust-lang/rfcs/blame/master/text/0529-conversion-traits.md#L249) and similar techniques are not uncommon in C++ template libraries. This patch goes to the extremes and applies the transformation even to smaller functions<sup>1</sup> for purity of the experiment. *Some of them can be rolled back* if considered too ridiculous. <sup>1</sup> However who knows how small are these functions are after inlining and everything. The functions in question are mostly `fs`/`os` functions and not used especially often with variety of argument types, so the code size reduction is rather small (but consistent). Here are the sizes of stage2 artifacts before and after the patch: https://gist.github.com/petrochenkov/e76a6b280f382da13c5d https://gist.github.com/petrochenkov/6cc28727d5256dbdfed0 Note: All the `inner` functions are concrete and unavailable for cross-crate inlining, some of them may need `#[inline]` annotations in the future. r? @aturon
2015-09-11std: Stabilize/deprecate features for 1.4Alex Crichton-11/+7
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes #27277 Closes #27718 Closes #27736 Closes #27764 Closes #27765 Closes #27766 Closes #27767 Closes #27768 Closes #27769 Closes #27771 Closes #27773 Closes #27775 Closes #27776 Closes #27785 Closes #27792 Closes #27795 Closes #27797
2015-09-09Reduce code bloat from conversion traits in function parametersVadim Petrochenkov-11/+14
2015-09-03std: Update CString::{into,from}_raw with `*mut T`Alex Crichton-8/+5
Conventionally in C `*mut T` is a transfer of ownership where `*const T` is a loan, so `*mut T` is likely the more appropriate return type for these functions. Additionally, this more closely mirrors the APIs on `Box` for this sort of functionality. cc #27769
2015-08-18std: Rename `cstr_memory` feature to use "raw"Alex Crichton-5/+28
This commit renames the `CString::{into_ptr, from_ptr}` methods to `into_raw` and `from_raw` to mirror the corresponding methods on `Box` and the naming of "raw" for `from_raw_parts` on slices and vectors. cc #27769
2015-08-15std: Add issues to all unstable featuresAlex Crichton-13/+15
2015-08-12Remove all unstable deprecated functionalityAlex Crichton-5/+7
This commit removes all unstable and deprecated functions in the standard library. A release was recently cut (1.3) which makes this a good time for some spring cleaning of the deprecated functions.
2015-08-11Register new snapshotsAlex Crichton-3/+0
* Lots of core prelude imports removed * Makefile support for MSVC env vars and Rust crates removed * Makefile support for morestack removed
2015-08-09Make `slice::transmute*` privateTobias Bucher-1/+1
2015-08-09Replace many uses of `mem::transmute` with more specific functionsTobias Bucher-4/+8
The replacements are functions that usually use a single `mem::transmute` in their body and restrict input and output via more concrete types than `T` and `U`. Worth noting are the `transmute` functions for slices and the `from_utf8*` family for mutable slices. Additionally, `mem::transmute` was often used for casting raw pointers, when you can already cast raw pointers just fine with `as`.
2015-08-03syntax: Implement #![no_core]Alex Crichton-1/+2
This commit is an implementation of [RFC 1184][rfc] which tweaks the behavior of the `#![no_std]` attribute and adds a new `#![no_core]` attribute. The `#![no_std]` attribute now injects `extern crate core` at the top of the crate as well as the libcore prelude into all modules (in the same manner as the standard library's prelude). The `#![no_core]` attribute disables both std and core injection. [rfc]: https://github.com/rust-lang/rfcs/pull/1184
2015-07-28Implement Clone for Box<[T]> where T: CloneJonathan Reem-9/+1
Closes #25097
2015-07-11Use escaped byte string representation for CString DebugUlrik Sverdrup-4/+16
Faithfully represent the contents of the CString and CStr in their Debug impl, by treating them as byte strings with our default escaping to ascii representation. Add impl Debug for Cstr. Fixes #26964.
2015-07-09Test that CStr and CString have equivalent hashes.Jonathan Reem-0/+15
2015-07-09Implement Borrow<CStr> for CString and ToOwned for CStrJonathan Reem-1/+24
This allows CString and CStr to be used with the Cow type, which is extremely useful when interfacing with C libraries that make extensive use of C-style strings.
2015-06-17Add comment about stabilizing CString::from_ptrAlex Crichton-0/+4
This naming needs to consider the raw vs ptr naming of Box/CStr/CString/slice/etc.
2015-06-17More test fixes and fallout of stability changesAlex Crichton-3/+2
2015-06-17std: Split the `std_misc` featureAlex Crichton-1/+0
2015-06-05Add methods for handing CStrings back and forth to CJake Goulding-1/+29
2015-06-05Convert CString to a Box<[u8]>Jake Goulding-4/+13
2015-05-23Auto merge of #25416 - kballard:ffi-cstr-to-str-convenience, r=alexcrichtonbors-0/+72
This was motivated by http://www.evanmiller.org/a-taste-of-rust.html. A common problem when working with FFI right now is converting from raw C strings into `&str` or `String`. Right now you're required to say something like let cstr = unsafe { CStr::from_ptr(ptr) }; let result = str::from_utf8(cstr.to_bytes()); This is slightly awkward, and is not particularly intuitive for people who haven't used the ffi module before. We can do a bit better by providing some convenience methods on CStr: fn to_str(&self) -> Result<&str, str::Utf8Error> fn to_string_lossy(&self) -> Cow<str> This will make it immediately apparent to new users of CStr how to get a string from a raw C string, so they can say: let s = unsafe { CStr::from_ptr(ptr).to_string_lossy() };
2015-05-22Add some convenience methods to go from CStr -> strKevin Ballard-0/+72
A common problem when working with FFI right now is converting from raw C strings into `&str` or `String`. Right now you're required to say something like let cstr = unsafe { CStr::from_ptr(ptr) }; let result = str::from_utf8(cstr.to_bytes()); This is slightly awkward, and is not particularly intuitive for people who haven't used the ffi module before. We can do a bit better by providing some convenience methods on CStr: fn to_str(&self) -> Result<&str, str::Utf8Error> fn to_string_lossy(&self) -> Cow<str> This will make it immediately apparent to new users of CStr how to get a string from a raw C string, so they can say: let s = unsafe { CStr::from_ptr(ptr).to_string_lossy() };
2015-05-16Simplify CString doc commentBen Striegel-2/+1
No need for `&b"foo"[..]` to make a CString, `"foo"` will do.
2015-04-21std: Remove deprecated AsOsStr/Str/AsSlice traitsAlex Crichton-57/+0
Cleaning out more deprecated items
2015-04-15Fix some typos.Ms2ger-1/+1
2015-04-14rollup merge of #24377: apasel422/docsAlex Crichton-19/+19
Conflicts: src/libstd/net/ip.rs src/libstd/sys/unix/fs.rs src/libstd/sys/unix/mod.rs src/libstd/sys/windows/mod.rs
2015-04-14rollup merge of #24350: tbelaire/cstring-doc-from-vecAlex Crichton-3/+4
It looks like `from_vec` was subsumed by new at some point, but the documentation still refers to it as `from_vec`. This updates the documentation for `from_vec_unchecked` so that it properly says that it's the unchecked version of `new`. Also, from_vec_unchecked requires a actual Vec<u8> while new can take anything that is Into<Vec<u8>>, so I also mention that in the documentation. Since this is documentation: r? @steveklabnik
2015-04-14std: Remove old_io/old_path/rand modulesAlex Crichton-30/+0
This commit entirely removes the old I/O, path, and rand modules. All functionality has been deprecated and unstable for quite some time now!
2015-04-13pluralize doc comment verbs and add missing periodsAndrew Paseltiner-19/+19
2015-04-12References to `CString::from_vec` changed to `new`Theo Belaire-3/+4
It looks like `from_vec` was subsumed by new at some point, but the documentation still refers to it as `from_vec`. This updates the documentation for `from_vec_unchecked` so that it properly says that it's the unchecked version of `new`. Also, from_vec_unchecked requires a actual Vec<u8> while new can take anything that is Into<Vec<u8>>, so I also mention that in the documentation.
2015-03-31rollup merge of #23919: alexcrichton/stabilize-io-errorAlex Crichton-1/+1
Conflicts: src/libstd/fs/tempdir.rs src/libstd/io/error.rs
2015-03-31std: Stabilize last bits of io::ErrorAlex Crichton-1/+1
This commit stabilizes a few remaining bits of the `io::Error` type: * The `Error::new` method is now stable. The last `detail` parameter was removed and the second `desc` parameter was generalized to `E: Into<Box<Error>>` to allow creating an I/O error from any form of error. Currently there is no form of downcasting, but this will be added in time. * An implementation of `From<&str> for Box<Error>` was added to liballoc to allow construction of errors from raw strings. * The `Error::raw_os_error` method was stabilized as-is. * Trait impls for `Clone`, `Eq`, and `PartialEq` were removed from `Error` as it is not possible to use them with trait objects. This is a breaking change due to the modification of the `new` method as well as the removal of the trait implementations for the `Error` type. [breaking-change]
2015-03-31Test fixes and rebase conflicts, round 2Alex Crichton-1/+1
2015-03-31rollup merge of #23873: alexcrichton/remove-deprecatedAlex Crichton-128/+3
Conflicts: src/libcollectionstest/fmt.rs src/libcollectionstest/lib.rs src/libcollectionstest/str.rs src/libcore/error.rs src/libstd/fs.rs src/libstd/io/cursor.rs src/libstd/os.rs src/libstd/process.rs src/libtest/lib.rs src/test/run-pass-fulldeps/compiler-calls.rs
2015-03-31rollup merge of #23879: seanmonstar/del-from-errorAlex Crichton-5/+5
Conflicts: src/libcore/error.rs