Coding practices are a source of a lot of arguments among programmers. Coding standards, to some degree, help us to put certain questions to bed and resolve stylistic debates. No coding standard makes everyone happy. (And even their existence is sure to make some unhappy.) What follows are the standards we put together on the Core team, which have become the general coding standard for all programming teams on new code development. We’ve tried to balance the need for creating a common, recognizable and readable code base with not unduly burdening the programmer with minor code formatting concerns.
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
| #[derive(Debug, PartialEq, Eq)] | |
| pub struct Aaa { | |
| pub field1: usize, | |
| pub field2: i32, | |
| } | |
| impl Default for Aaa { | |
| /// ``` | |
| /// # use aaa::Aaa; | |
| /// # let a = |
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
| #[derive(Debug)] | |
| struct Person { | |
| name: String, | |
| age: u32, | |
| } | |
| impl Person { | |
| fn new(name: String, age: u32) -> Self { | |
| // return Person { name: name, age: age }; | |
| Self { name, age } |
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
| // WARNING: This output format is intended for human consumers only | |
| // and is subject to change without notice. Knock yourself out. | |
| fn <impl at src/lib.rs:5:1: 9:2>::from(_1: i16) -> Koko { | |
| let mut _0: Koko; // return place | |
| let mut _2: i16; | |
| bb0: { | |
| StorageLive(_2); // bb0[0]: scope 0 at src/lib.rs:7:23: 7:28 | |
| _2 = _1; // bb0[1]: scope 0 at src/lib.rs:7:23: 7:28 | |
| _0 = Koko { field: move _2 }; // bb0[2]: scope 0 at src/lib.rs:7:9: 7:30 |
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
| extern crate bindgen; | |
| use std::env; | |
| use std::path::{Path, PathBuf}; | |
| fn main() { | |
| println!("cargo:rustc-link-search=framework=/System/Library/Frameworks/"); | |
| println!("cargo:rustc-link-lib=framework=OpenCL"); | |
| let headers = env::var("CARGO_MANIFEST_DIR").unwrap() + "/opencl22/CL/"; |
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
| test async ... bench: 25,129,522 ns/iter (+/- 1,948,456) | |
| test async_cpupool ... bench: 13,895,220 ns/iter (+/- 2,412,441) | |
| test async_cpupool_cpus ... bench: 16,449,300 ns/iter (+/- 7,062,024) | |
| test async_cpupool_many ... bench: 14,118,352 ns/iter (+/- 3,170,100) | |
| test async_cpus ... bench: 11,057,663 ns/iter (+/- 1,546,785) | |
| test async_many ... bench: 14,304,595 ns/iter (+/- 1,966,185) | |
| test corona ... bench: 34,898,721 ns/iter (+/- 204,006,257) | |
| test corona_blocking_wrapper ... bench: 35,851,174 ns/iter (+/- 76,716,240) | |
| test corona_blocking_wrapper_cpus ... bench: 12,601,478 ns/iter (+/- 1,368,466) | |
| test corona_blocking_wrapper_many ... bench: 20,098,071 ns/iter (+/- 84,982,750) |
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
| pub enum Arg { | |
| Int(i32), | |
| Float(f32), | |
| String(String), | |
| Ptr(isize), | |
| } | |
| pub enum KernelError { | |
| KernelInvalid, | |
| } |
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
| // prefer using IntoIterator ? | |
| fn split_first<T, I>(mut iter: I) -> Option<(T, I)> | |
| where I: Iterator<Item=T> | |
| { | |
| match iter.next() { | |
| Some(first) => Some((first, iter)), | |
| None => None, | |
| } | |
| } |
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
| fn all_eq<T: Eq>(slice: &[T]) -> bool { | |
| match slice.split_first() { | |
| Some((first, others)) => others.iter().all(|x| x == first), | |
| None => true, | |
| } | |
| } | |
| #[test] | |
| fn all_eq_easy_eq() { | |
| assert!(all_eq(&[1, 1, 1, 1, 1])); |
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
| fn linear_group(&self) -> LinearGroupBy<T, fn(&T, &T) -> bool> | |
| where T: Ord | |
| { | |
| LinearGroupBy::new(self, |a, b| a == b) | |
| } |