| 1 | // Ownership extensions for strings. |
| 2 | // Only included when -ownership flag is passed (via -d ownership). |
| 3 | // Provides .to_owned() which creates an owned string with move semantics. |
| 4 | module builtin |
| 5 | |
| 6 | // IClone marks values that provide explicit clone semantics in ownership mode. |
| 7 | // |
| 8 | // This is a marker interface. Concrete types still define their own `clone()` |
| 9 | // methods with concrete return types. |
| 10 | pub interface IClone {} |
| 11 | |
| 12 | // to_owned creates an owned copy of the string. |
| 13 | // When ownership checking is enabled, owned strings have move semantics: |
| 14 | // assigning an owned string to another variable moves ownership, |
| 15 | // making the original variable invalid. |
| 16 | pub fn (s string) to_owned() string { |
| 17 | return s.clone() |
| 18 | } |
| 19 | |