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

rust Number/String/pointer/usize/chart 内置属性 #773

Open
cisen opened this issue Nov 17, 2019 · 4 comments
Open

rust Number/String/pointer/usize/chart 内置属性 #773

cisen opened this issue Nov 17, 2019 · 4 comments
Labels

Comments

@cisen
Copy link
Owner

cisen commented Nov 17, 2019

总结

Number

通用

  • floor,浮点数向下取整
  • ceil, 浮点数向上取整
  • round,根据中间数向上或向下取值
  • trunc,返回浮点数的整数部分
  • fract, 返回浮点数的小数部分
  • abs,绝对值
  • signum
  • copysign
  • mul_add
  • div_euclid
  • rem_euclid
  • powi
  • powf
  • sqrt
  • exp
  • exp2
  • ln
  • log
  • log2
  • log10
  • abs_sub
  • cbrt
  • hypot
  • sin
  • cos
  • tan
  • asin
  • acos
  • atan
  • atan2
  • sin_cos
  • exp_m1
  • ln_1p
  • sinh
  • cosh
  • tanh
  • asinh
  • atanh
  • clamp
  • is_nan
  • is_infinite
  • is_finite
  • is_normal
  • classify
  • is_sign_positive
  • is_sign_negative
  • recip
  • to_degrees
  • to_radians
  • max
  • min
  • to_bits
  • from_bits
  • to_be_bytes
  • to_le_bytes
  • to_ne_bytes
  • from_be_bytes
  • from_le_bytes
  • from_ne_bytes
  • wrapping_add
    https://doc.rust-lang.org/nightly/std/primitive.i32.html#method.wrapping_add
    环绕该数据类型边界进行加减,比如边界是100,则100+2 === 2
assert_eq!(100i32.wrapping_add(27), 127);
assert_eq!(i32::max_value().wrapping_add(2), i32::min_value() + 1);

f32

@cisen cisen added the Rust label Nov 17, 2019
@cisen
Copy link
Owner Author

cisen commented Nov 18, 2019

String

通用

  • len 返回字符串长度
  • is_empty 是否是空字符串(已经定义)
  • is_char_boundary
  • as_bytes 将字符串转化为一个字节的片段。可以使用str::from_utf8转化回字符串
  • as_bytes_mut
  • as_ptr
  • as_mut_ptr
  • get
  • get_mut
  • get_unchecked
  • get_unchecked_mut
  • slice_unchecked
  • slice_mut_unchecked
  • split_at
  • split_at_mut
  • chars
  • char_indices
  • bytes
  • split_whitespace
  • split_ascii_whitespace
  • lines
  • lines_any
  • encode_utf16
  • contains
  • starts_with
  • ends_with
  • find
  • rfind
  • split
  • rsplit
  • split_terminator
  • rsplit_terminator
  • splitn
  • rsplitn
  • matches
  • rmatches
  • match_indices
  • rmatch_indices
  • trim
  • trim_start
  • trim_end
  • trim_left
  • trim_right
  • trim_matches
  • trim_start_matches
  • trim_end_matches
  • trim_left_matches
  • trim_right_matches
  • parse
  • is_ascii
  • eq_ignore_ascii_case
  • make_ascii_uppercase
  • make_ascii_lowercase
  • escape_debug
  • escape_default
  • escape_unicode
  • into_boxed_bytes
  • replace
  • replacen
  • to_lowercase
  • to_uppercase
  • into_string
  • repeat
  • to_ascii_uppercase
  • to_ascii_lowercase

@cisen
Copy link
Owner Author

cisen commented Nov 18, 2019

pointer 指针

https://doc.rust-lang.org/std/primitive.pointer.html

方法

  • add
  • add
  • align_offset
  • align_offset
  • as_mut
  • as_ref
  • as_ref
  • cast
  • cast
  • copy_from
  • copy_from_nonoverlapping
  • copy_to
  • copy_to
  • copy_to_nonoverlapping
  • copy_to_nonoverlapping
  • drop_in_place
  • is_null
  • is_null
  • offset
  • offset
  • offset_from
  • offset_from
  • read
  • read
  • read_unaligned
  • read_unaligned
  • read_volatile
  • read_volatile
  • replace
  • sub
  • sub
  • swap
  • wrapping_add
  • https://doc.rust-lang.org/std/primitive.pointer.html#method.wrapping_add
// Iterate using a raw pointer in increments of two elements
let data = [1u8, 2, 3, 4, 5];
let mut ptr: *const u8 = data.as_ptr();
let step = 2;
let end_rounded_up = ptr.wrapping_add(6);

// This loop prints "1, 3, 5, "
while ptr != end_rounded_up {
    unsafe {
        print!("{}, ", *ptr);
    }
    ptr = ptr.wrapping_add(step);
}
  • wrapping_offset
  • wrapping_offset
  • wrapping_offset_from
  • wrapping_offset_from
  • wrapping_sub
  • wrapping_sub
  • write
  • write_bytes
  • write_unaligned

@cisen
Copy link
Owner Author

cisen commented Nov 18, 2019

usize/isize

方法

  • checked_add
  • checked_div
  • checked_div_euclid
  • checked_mul
    • 检查两个数相乘是否超过该类型的最大值
  • checked_neg
  • checked_next_power_of_two
  • checked_pow
  • checked_rem
  • checked_rem_euclid
  • checked_shl
  • checked_shr
  • checked_sub
  • count_ones
  • count_zeros
  • div_euclid
  • from_be
  • from_be_bytes
  • from_le
  • from_le_bytes
  • from_ne_bytes
  • from_str_radix
  • is_power_of_two
  • leading_zeros
  • max_value
  • min_value
  • next_power_of_two
  • overflowing_add
  • overflowing_div
  • overflowing_div_euclid
  • overflowing_mul
  • overflowing_neg
  • overflowing_pow
  • overflowing_rem
  • overflowing_rem_euclid
  • overflowing_shl
  • overflowing_shr
  • overflowing_sub
  • pow
  • rem_euclid
  • reverse_bits
  • rotate_left
  • rotate_right
  • saturating_add
  • saturating_mul
  • saturating_pow
  • saturating_sub
  • swap_bytes
  • to_be
  • to_be_bytes
  • to_le
  • to_le_bytes
  • to_ne_bytes
  • trailing_zeros
  • wrapping_add
  • wrapping_div
  • wrapping_div_euclid
  • wrapping_mul
  • wrapping_neg
  • wrapping_next_power_of_two
  • wrapping_pow
  • wrapping_rem
  • wrapping_rem_euclid
  • wrapping_shl
  • wrapping_shr
  • wrapping_sub

@cisen
Copy link
Owner Author

cisen commented Nov 18, 2019

char

     let x = 'x';
     let two_hearts = ' ';

不像其他语言,这意味着Rust的字符不是单个字节,而是四个。

方法

encode_utf16
encode_utf8
eq_ignore_ascii_case
escape_debug
escape_default
escape_unicode
is_alphabetic
is_alphanumeric
is_ascii
is_ascii_alphabetic
is_ascii_alphanumeric
is_ascii_control
is_ascii_digit
is_ascii_graphic
is_ascii_hexdigit
is_ascii_lowercase
is_ascii_punctuation
is_ascii_uppercase
is_ascii_whitespace
is_control
is_digit
is_lowercase
is_numeric
is_uppercase
is_whitespace
len_utf16
len_utf8
make_ascii_lowercase
make_ascii_uppercase
to_ascii_lowercase
to_ascii_uppercase
to_digit
to_lowercase
to_uppercase

@cisen cisen changed the title rust Number/String 内置属性 rust Number/String/pointer/usize/chart 内置属性 Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant