v2 / vlib / builtin / string_d_ownership.v
18 lines · 16 sloc · 710 bytes · f882c8174f24df66dd40c8cbb2d14bd503ee9937
Raw
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.
4module 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.
10pub 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.
16pub fn (s string) to_owned() string {
17 return s.clone()
18}
19