Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
10c6737e
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
10c6737e
编写于
11月 23, 2015
作者:
S
Steve Klabnik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix up docs for char
Part of
https://github.com/rust-lang/rust/issues/29333
上级
8e9a9752
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
80 addition
and
14 deletion
+80
-14
src/librustc_unicode/char.rs
src/librustc_unicode/char.rs
+8
-3
src/libstd/primitive_docs.rs
src/libstd/primitive_docs.rs
+72
-11
未找到文件。
src/librustc_unicode/char.rs
浏览文件 @
10c6737e
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// except according to those terms.
//!
A Unicode scalar value
//!
Unicode scalar values
//!
//!
//! This module provides the `CharExt` trait, as well as its
//! This module provides the `CharExt` trait, as well as its
//! implementation for the primitive `char` type, in order to allow
//! implementation for the primitive `char` type, in order to allow
...
@@ -244,11 +244,12 @@ pub fn to_digit(self, radix: u32) -> Option<u32> {
...
@@ -244,11 +244,12 @@ pub fn to_digit(self, radix: u32) -> Option<u32> {
/// character, as `char`s.
/// character, as `char`s.
///
///
/// All characters are escaped with Rust syntax of the form `\\u{NNNN}`
/// All characters are escaped with Rust syntax of the form `\\u{NNNN}`
/// where `NNNN` is the shortest hexadecimal representation of the code
/// where `NNNN` is the shortest hexadecimal representation.
/// point.
///
///
/// # Examples
/// # Examples
///
///
/// Basic usage:
///
/// ```
/// ```
/// for c in '❤'.escape_unicode() {
/// for c in '❤'.escape_unicode() {
/// print!("{}", c);
/// print!("{}", c);
...
@@ -384,6 +385,8 @@ pub fn len_utf8(self) -> usize {
...
@@ -384,6 +385,8 @@ pub fn len_utf8(self) -> usize {
///
///
/// # Examples
/// # Examples
///
///
/// Basic usage:
///
/// ```
/// ```
/// let n = 'ß'.len_utf16();
/// let n = 'ß'.len_utf16();
/// assert_eq!(n, 1);
/// assert_eq!(n, 1);
...
@@ -858,6 +861,8 @@ pub struct DecodeUtf16<I>
...
@@ -858,6 +861,8 @@ pub struct DecodeUtf16<I>
///
///
/// # Examples
/// # Examples
///
///
/// Basic usage:
///
/// ```
/// ```
/// #![feature(decode_utf16)]
/// #![feature(decode_utf16)]
///
///
...
...
src/libstd/primitive_docs.rs
浏览文件 @
10c6737e
...
@@ -16,21 +16,82 @@ mod prim_bool { }
...
@@ -16,21 +16,82 @@ mod prim_bool { }
#[doc(primitive
=
"char"
)]
#[doc(primitive
=
"char"
)]
//
//
/// A
Unicode scalar valu
e.
/// A
character typ
e.
///
///
/// A `char` represents a
/// The `char` type represents a single character. More specifically, since
/// *[Unicode scalar
/// 'character' isn't a well-defined concept in Unicode, `char` is a '[Unicode
/// value](http://www.unicode.org/glossary/#unicode_scalar_value)*, as it can
/// scalar value]', which is similar to, but not the same as, a '[Unicode code
/// contain any Unicode code point except high-surrogate and low-surrogate code
/// point]'.
/// points.
///
///
/// As such, only values in the ranges \[0x0,0xD7FF\] and \[0xE000,0x10FFFF\]
/// [Unicode scalar value]: http://www.unicode.org/glossary/#unicode_scalar_value
/// (inclusive) are allowed. A `char` can always be safely cast to a `u32`;
/// [Unicode code point]: http://www.unicode.org/glossary/#code_point
/// however the converse is not always true due to the above range limits
/// and, as such, should be performed via the `from_u32` function.
///
///
/// *[See also the `std::char` module](char/index.html).*
/// This documentation describes a number of methods and trait implementations on the
/// `char` type. For technical reasons, there is additional, separate
/// documentation in [the `std::char` module](char/index.html) as well.
///
///
/// # Representation
///
/// `char` is always four bytes in size. This is a different representation than
/// a given character would have as part of a [`String`], for example:
///
/// ```
/// let v = vec!['h', 'e', 'l', 'l', 'o'];
///
/// // five elements times four bytes for each element
/// assert_eq!(20, v.len() * std::mem::size_of::<char>());
///
/// let s = String::from("hello");
///
/// // five elements times one byte per element
/// assert_eq!(5, s.len() * std::mem::size_of::<u8>());
/// ```
///
/// [`String`]: string/struct.String.html
///
/// As always, remember that a human intuition for 'character' may not map to
/// Unicode's definitions. For example, emoji symbols such as '❤️' are more than
/// one byte; ❤️ in particular is six:
///
/// ```
/// let s = String::from("❤️");
///
/// // six bytes times one byte for each element
/// assert_eq!(6, s.len() * std::mem::size_of::<u8>());
/// ```
///
/// This also means it won't fit into a `char`, and so trying to create a
/// literal with `let heart = '❤️';` gives an error:
///
/// ```text
/// error: character literal may only contain one codepoint: '❤
/// let heart = '❤️';
/// ^~
/// ```
///
/// Another implication of this is that if you want to do per-`char`acter
/// processing, it can end up using a lot more memory:
///
/// ```
/// let s = String::from("love: ❤️");
/// let v: Vec<char> = s.chars().collect();
///
/// assert_eq!(12, s.len() * std::mem::size_of::<u8>());
/// assert_eq!(32, v.len() * std::mem::size_of::<char>());
/// ```
///
/// Or may give you results you may not expect:
///
/// ```
/// let s = String::from("❤️");
///
/// let mut iter = s.chars();
///
/// // we get two chars out of a single ❤️
/// assert_eq!(Some('\u{2764}'), iter.next());
/// assert_eq!(Some('\u{fe0f}'), iter.next());
/// assert_eq!(None, iter.next());
/// ```
mod
prim_char
{
}
mod
prim_char
{
}
#[doc(primitive
=
"unit"
)]
#[doc(primitive
=
"unit"
)]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录