* [rust-dev] A question about implementation of &str
@ 2014-12-03 17:34 C K Kashyap
2014-12-03 17:57 ` Matthieu Monrocq
0 siblings, 1 reply; 3+ messages in thread
From: C K Kashyap @ 2014-12-03 17:34 UTC (permalink / raw)
To: rust-dev
[-- Attachment #1: Type: text/plain, Size: 670 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 1032 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rust-dev] A question about implementation of &str
2014-12-03 17:34 [rust-dev] A question about implementation of &str C K Kashyap
@ 2014-12-03 17:57 ` Matthieu Monrocq
2014-12-04 3:04 ` C K Kashyap
0 siblings, 1 reply; 3+ messages in thread
From: Matthieu Monrocq @ 2014-12-03 17:57 UTC (permalink / raw)
To: C K Kashyap; +Cc: rust-dev
[-- Attachment #1: Type: text/plain, Size: 1337 bytes --]
&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 <ckkashyap@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
>
>
[-- Attachment #2: Type: text/html, Size: 2141 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rust-dev] A question about implementation of &str
2014-12-03 17:57 ` Matthieu Monrocq
@ 2014-12-04 3:04 ` C K Kashyap
0 siblings, 0 replies; 3+ messages in thread
From: C K Kashyap @ 2014-12-04 3:04 UTC (permalink / raw)
To: Matthieu Monrocq; +Cc: rust-dev
[-- Attachment #1: Type: text/plain, Size: 1503 bytes --]
Thanks Matthieu.
Regards,
Kashyap
On Wed, Dec 3, 2014 at 11:27 PM, Matthieu Monrocq <
matthieu.monrocq@gmail.com> wrote:
> &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 <ckkashyap@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
>>
>>
>
[-- Attachment #2: Type: text/html, Size: 2666 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-12-04 3:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-03 17:34 [rust-dev] A question about implementation of &str C K Kashyap
2014-12-03 17:57 ` Matthieu Monrocq
2014-12-04 3:04 ` C K Kashyap
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox