i’ve got an path API that has an appending(_:)
API that’s defined as such:
extension QualifiedPath
{
__consuming
func appending(_ component:String) -> Self
{
var path:Self = self
path.suffix.append(component)
return path
}
}
as i understand it, the __consuming
modifier allows this to happen without triggering copy-on-write.
now, i want to make this API an operator instead of an instance method:
extension QualifiedPath
{
public static
func / (self:Self, component:String) -> Self
{
self.appending(component)
}
}
because self
now lives for the duration of the operator call (regardless of __owned
apparently), this suffers from copy-on-write when called from outside the module.
as with everything else in swift, the problem might go away if you spray enough @inlinable
on it.
extension QualifiedPath
{
@usableFromInline internal __consuming
func appending(_ component:String) -> Self
{
var path:Self = self
path.suffix.append(component)
return path
}
@inlinable public static
func / (self:Self, component:String) -> Self
{
self.appending(component)
}
}
but is there a more hygienic way to implement this?