&str is simply a pair (length, pointer).

The reason that even for a literal the length is packed as an argument is
that &str does not ONLY work for literals (complete type &'static str) but
for any slice of characters, such as those produced by String::as_slice()
in which case the lifetime is different (only live as long as the
particular String instance) and the length is not necessarily known at
compile-time.

On Wed, Dec 3, 2014 at 6:34 PM, C K Kashyap <ckkash...@gmail.com> wrote:

> Hi,
> I am stuck in my kernel development where I find that I am not able to
> iterate over a &str. The code is here -
> https://github.com/ckkashyap/unix/blob/master/kernel/uart.rs in the
> function uart_putc I find that the for-loop loops the right number of
> times but it does not print the right character. To me it appears to be a
> linking problem with my kernel. However, to debug this issue I wanted to
> get a better understanding of what happens when we iterate over &str. I was
> surprised to see that the length of the string literal that is determined
> at compile time is being sent as an argument.
>
> I'd appreciate any insights into how I can debug this.
>
> Regards,
> Kashyap
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to