Sort a list of object identifiers: Difference between revisions
Content added Content deleted
(Added Ada entry.) |
(Added Rust) |
||
Line 1,239: | Line 1,239: | ||
].sort_by{|oid| Gem::Version.new(oid) }</lang> |
].sort_by{|oid| Gem::Version.new(oid) }</lang> |
||
with identical output. |
with identical output. |
||
=={{header|Rust}}== |
|||
<lang Rust>fn split(s: &str) -> impl Iterator<Item = u64> + '_ { |
|||
s.split('.').map(|x| x.parse().unwrap()) |
|||
} |
|||
fn main() { |
|||
let mut oids = vec![ |
|||
"1.3.6.1.4.1.11.2.17.19.3.4.0.10", |
|||
"1.3.6.1.4.1.11.2.17.5.2.0.79", |
|||
"1.3.6.1.4.1.11.2.17.19.3.4.0.4", |
|||
"1.3.6.1.4.1.11150.3.4.0.1", |
|||
"1.3.6.1.4.1.11.2.17.19.3.4.0.1", |
|||
"1.3.6.1.4.1.11150.3.4.0", |
|||
]; |
|||
oids.sort_by(|a, b| Iterator::cmp(split(a), split(b))); |
|||
println!("{:#?}", oids); |
|||
}</lang> |
|||
{{out}} |
|||
<pre>[ |
|||
"1.3.6.1.4.1.11.2.17.5.2.0.79", |
|||
"1.3.6.1.4.1.11.2.17.19.3.4.0.1", |
|||
"1.3.6.1.4.1.11.2.17.19.3.4.0.4", |
|||
"1.3.6.1.4.1.11.2.17.19.3.4.0.10", |
|||
"1.3.6.1.4.1.11150.3.4.0", |
|||
"1.3.6.1.4.1.11150.3.4.0.1" |
|||
]</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |