<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>bamch0h</author_name>
  <author_url>https://blog.hatena.ne.jp/bamch0h/</author_url>
  <blog_title>bamchoh’s diary</blog_title>
  <blog_url>https://bamch0h.hatenablog.com/</blog_url>
  <categories>
    <anon>Rust</anon>
  </categories>
  <description>文字リテラル Hello から String を作成し、一部を文字列スライスとして切り出した後、String スコープ外で文字列スライスを使う。というシナリオを考えたが、以下のようにコンパイルエラーが発生する。文字列スライスが参照している大元の String がスコープを抜ける際に Drop してしまうためだ。 fn main() { let sub: &amp;str; { let s = String::from(&quot;Hello&quot;); sub = &amp;s[0..2]; // ^ borrowed value does not live long enough } println!(&quot;{}&quot;, sub)…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fbamch0h.hatenablog.com%2Fentry%2F2022%2F03%2F07%2F130755&quot; title=&quot; 所有権? String と 文字列スライス - bamchoh’s diary&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2022-03-07 13:07:55</published>
  <title> 所有権? String と 文字列スライス</title>
  <type>rich</type>
  <url>https://bamch0h.hatenablog.com/entry/2022/03/07/130755</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
