What does [..] mean for Rust slices and what is it called? [duplicate] Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!What does the “two periods” operator mean in the context of a subscript inside of square brackets?What is the difference between String and string in C#?Understanding slice notationJavaScript chop/slice/trim off last character in stringWhat does %w(array) mean?Why does comparing strings using either '==' or 'is' sometimes produce a different result?What is the difference between String.slice and String.substring?Does Python have a string 'contains' substring method?Fastest way to duplicate an array in JavaScript - slice vs. 'for' loopWhy does this code using random strings print “hello world”?Concatenate two slices in Go
malloc in main() or malloc in another function: allocating memory for a struct and its members
Did John Wesley plagiarize Matthew Henry...?
Short story about astronauts fertilizing soil with their own bodies
Why not use the yoke to control yaw, as well as pitch and roll?
Centre cell contents vertically
What does the writing on Poe's helmet say?
3D Masyu - A Die
Why shouldn't this prove the Prime Number Theorem?
What are some likely causes to domain member PC losing contact to domain controller?
What is the proper term for etching or digging of wall to hide conduit of cables
Is this Kuo-toa homebrew race balanced?
How to make an animal which can only breed for a certain number of generations?
Problem with display of presentation
A proverb that is used to imply that you have unexpectedly faced a big problem
Can two people see the same photon?
Is it OK to use the testing sample to compare algorithms?
Is a copyright notice with a non-existent name be invalid?
Are there any irrational/transcendental numbers for which the distribution of decimal digits is not uniform?
How to resize main filesystem
The test team as an enemy of development? And how can this be avoided?
Statistical analysis applied to methods coming out of Machine Learning
Pointing to problems without suggesting solutions
Find general formula for the terms
When does a function NOT have an antiderivative?
What does [..] mean for Rust slices and what is it called? [duplicate]
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!What does the “two periods” operator mean in the context of a subscript inside of square brackets?What is the difference between String and string in C#?Understanding slice notationJavaScript chop/slice/trim off last character in stringWhat does %w(array) mean?Why does comparing strings using either '==' or 'is' sometimes produce a different result?What is the difference between String.slice and String.substring?Does Python have a string 'contains' substring method?Fastest way to duplicate an array in JavaScript - slice vs. 'for' loopWhy does this code using random strings print “hello world”?Concatenate two slices in Go
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
What does the “two periods” operator mean in the context of a subscript inside of square brackets?
2 answers
I've found this example in a README:
use std::env;
fn main()
let filename: &str = &env::args().nth(1).unwrap()[..];
let filename2: &str = &env::args().nth(1).unwrap();
println!(":?", filename);
println!(":?", filename2)
I'm interested in the first line: let filename ....
What does the [..] after the unwrap mean?
The second line let filename2 ... is my own test that both filename and filename2 are the same, or do I miss something?
What is this [..] called?
string rust slice
marked as duplicate by Shepmaster
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 13:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
What does the “two periods” operator mean in the context of a subscript inside of square brackets?
2 answers
I've found this example in a README:
use std::env;
fn main()
let filename: &str = &env::args().nth(1).unwrap()[..];
let filename2: &str = &env::args().nth(1).unwrap();
println!(":?", filename);
println!(":?", filename2)
I'm interested in the first line: let filename ....
What does the [..] after the unwrap mean?
The second line let filename2 ... is my own test that both filename and filename2 are the same, or do I miss something?
What is this [..] called?
string rust slice
marked as duplicate by Shepmaster
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 13:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
It's a range.
– jonrsharpe
Mar 22 at 12:55
2
Pedantically..is aRangeFull,[]is the indexing / slicing syntax. See also Appendix B: Operators and Symbols
– Shepmaster
Mar 22 at 13:42
1
It is not useless — it converts a&Stringinto a&strin this case. The: &strisn't needed, but it's probably to show the types to make it easier for people to understand the types in play. Your second line does the same thing viaDerefcoercion.
– Shepmaster
Mar 25 at 15:16
add a comment |
This question already has an answer here:
What does the “two periods” operator mean in the context of a subscript inside of square brackets?
2 answers
I've found this example in a README:
use std::env;
fn main()
let filename: &str = &env::args().nth(1).unwrap()[..];
let filename2: &str = &env::args().nth(1).unwrap();
println!(":?", filename);
println!(":?", filename2)
I'm interested in the first line: let filename ....
What does the [..] after the unwrap mean?
The second line let filename2 ... is my own test that both filename and filename2 are the same, or do I miss something?
What is this [..] called?
string rust slice
This question already has an answer here:
What does the “two periods” operator mean in the context of a subscript inside of square brackets?
2 answers
I've found this example in a README:
use std::env;
fn main()
let filename: &str = &env::args().nth(1).unwrap()[..];
let filename2: &str = &env::args().nth(1).unwrap();
println!(":?", filename);
println!(":?", filename2)
I'm interested in the first line: let filename ....
What does the [..] after the unwrap mean?
The second line let filename2 ... is my own test that both filename and filename2 are the same, or do I miss something?
What is this [..] called?
This question already has an answer here:
What does the “two periods” operator mean in the context of a subscript inside of square brackets?
2 answers
string rust slice
string rust slice
edited Mar 25 at 15:16
Shepmaster
163k16338485
163k16338485
asked Mar 22 at 12:53
zzeroozzeroo
3,33912536
3,33912536
marked as duplicate by Shepmaster
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 13:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Shepmaster
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 22 at 13:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
It's a range.
– jonrsharpe
Mar 22 at 12:55
2
Pedantically..is aRangeFull,[]is the indexing / slicing syntax. See also Appendix B: Operators and Symbols
– Shepmaster
Mar 22 at 13:42
1
It is not useless — it converts a&Stringinto a&strin this case. The: &strisn't needed, but it's probably to show the types to make it easier for people to understand the types in play. Your second line does the same thing viaDerefcoercion.
– Shepmaster
Mar 25 at 15:16
add a comment |
1
It's a range.
– jonrsharpe
Mar 22 at 12:55
2
Pedantically..is aRangeFull,[]is the indexing / slicing syntax. See also Appendix B: Operators and Symbols
– Shepmaster
Mar 22 at 13:42
1
It is not useless — it converts a&Stringinto a&strin this case. The: &strisn't needed, but it's probably to show the types to make it easier for people to understand the types in play. Your second line does the same thing viaDerefcoercion.
– Shepmaster
Mar 25 at 15:16
1
1
It's a range.
– jonrsharpe
Mar 22 at 12:55
It's a range.
– jonrsharpe
Mar 22 at 12:55
2
2
Pedantically
.. is a RangeFull, [] is the indexing / slicing syntax. See also Appendix B: Operators and Symbols– Shepmaster
Mar 22 at 13:42
Pedantically
.. is a RangeFull, [] is the indexing / slicing syntax. See also Appendix B: Operators and Symbols– Shepmaster
Mar 22 at 13:42
1
1
It is not useless — it converts a
&String into a &str in this case. The : &str isn't needed, but it's probably to show the types to make it easier for people to understand the types in play. Your second line does the same thing via Deref coercion.– Shepmaster
Mar 25 at 15:16
It is not useless — it converts a
&String into a &str in this case. The : &str isn't needed, but it's probably to show the types to make it easier for people to understand the types in play. Your second line does the same thing via Deref coercion.– Shepmaster
Mar 25 at 15:16
add a comment |
1 Answer
1
active
oldest
votes
A string can be used as an array of bytes. This addition does strictly nothing:
#![feature(core_intrinsics)]
fn print_type_of<T>(_: &T)
println!("", unsafe std::intrinsics::type_name::<T>() );
fn main()
let x = "abc";
print_type_of(&x); // &str
let x = &x[..];
print_type_of(&x); // &str
[..] takes the full range, and & takes a reference to it.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A string can be used as an array of bytes. This addition does strictly nothing:
#![feature(core_intrinsics)]
fn print_type_of<T>(_: &T)
println!("", unsafe std::intrinsics::type_name::<T>() );
fn main()
let x = "abc";
print_type_of(&x); // &str
let x = &x[..];
print_type_of(&x); // &str
[..] takes the full range, and & takes a reference to it.
add a comment |
A string can be used as an array of bytes. This addition does strictly nothing:
#![feature(core_intrinsics)]
fn print_type_of<T>(_: &T)
println!("", unsafe std::intrinsics::type_name::<T>() );
fn main()
let x = "abc";
print_type_of(&x); // &str
let x = &x[..];
print_type_of(&x); // &str
[..] takes the full range, and & takes a reference to it.
add a comment |
A string can be used as an array of bytes. This addition does strictly nothing:
#![feature(core_intrinsics)]
fn print_type_of<T>(_: &T)
println!("", unsafe std::intrinsics::type_name::<T>() );
fn main()
let x = "abc";
print_type_of(&x); // &str
let x = &x[..];
print_type_of(&x); // &str
[..] takes the full range, and & takes a reference to it.
A string can be used as an array of bytes. This addition does strictly nothing:
#![feature(core_intrinsics)]
fn print_type_of<T>(_: &T)
println!("", unsafe std::intrinsics::type_name::<T>() );
fn main()
let x = "abc";
print_type_of(&x); // &str
let x = &x[..];
print_type_of(&x); // &str
[..] takes the full range, and & takes a reference to it.
answered Mar 22 at 12:58
French BoiethiosFrench Boiethios
11.4k44081
11.4k44081
add a comment |
add a comment |
1
It's a range.
– jonrsharpe
Mar 22 at 12:55
2
Pedantically
..is aRangeFull,[]is the indexing / slicing syntax. See also Appendix B: Operators and Symbols– Shepmaster
Mar 22 at 13:42
1
It is not useless — it converts a
&Stringinto a&strin this case. The: &strisn't needed, but it's probably to show the types to make it easier for people to understand the types in play. Your second line does the same thing viaDerefcoercion.– Shepmaster
Mar 25 at 15:16