Add support for converting OptionalPath to Paths
Appending a Path or Paths to a slice of Paths is simple but appending an OptionalPath requires conditional logic which makes OptionalPaths harder to use. This change makes it easy to append the embedded Path, if any, to a slice of Paths. Bug: 179354495 Test: m nothing Change-Id: Ibf80a23043c846162e17c3a98b2590bca653b170
This commit is contained in:
@@ -287,6 +287,17 @@ func (p OptionalPath) Path() Path {
|
||||
return p.path
|
||||
}
|
||||
|
||||
// AsPaths converts the OptionalPath into Paths.
|
||||
//
|
||||
// It returns nil if this is not valid, or a single length slice containing the Path embedded in
|
||||
// this OptionalPath.
|
||||
func (p OptionalPath) AsPaths() Paths {
|
||||
if !p.valid {
|
||||
return nil
|
||||
}
|
||||
return Paths{p.path}
|
||||
}
|
||||
|
||||
// RelativeToTop returns an OptionalPath with the path that was embedded having been replaced by the
|
||||
// result of calling Path.RelativeToTop on it.
|
||||
func (p OptionalPath) RelativeToTop() OptionalPath {
|
||||
|
Reference in New Issue
Block a user