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;








0
















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?










share|improve this question















marked as duplicate by Shepmaster rust
Users with the  rust badge can single-handedly close rust questions as duplicates and reopen them as needed.

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 a RangeFull, [] 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 &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


















0
















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?










share|improve this question















marked as duplicate by Shepmaster rust
Users with the  rust badge can single-handedly close rust questions as duplicates and reopen them as needed.

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 a RangeFull, [] 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 &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














0












0








0









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?










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 rust
Users with the  rust badge can single-handedly close rust questions as duplicates and reopen them as needed.

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 rust
Users with the  rust badge can single-handedly close rust questions as duplicates and reopen them as needed.

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 a RangeFull, [] 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 &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













  • 1





    It's a range.

    – jonrsharpe
    Mar 22 at 12:55






  • 2





    Pedantically .. is a RangeFull, [] 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 &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








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













1 Answer
1






active

oldest

votes


















3














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.






share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    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.






    share|improve this answer



























      3














      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.






      share|improve this answer

























        3












        3








        3







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 12:58









        French BoiethiosFrench Boiethios

        11.4k44081




        11.4k44081















            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해