Skip to content

Commit efaf0b7

Browse files
committed
Support initializing Attribute with rule and initial value
1 parent 2a615c6 commit efaf0b7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/OpenAttributeGraph/Attribute/Attribute/Attribute.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,27 @@ extension Attribute {
289289
}
290290
}
291291

292+
public init<R: Rule>(_ rule: R, initialValue: Value) where R.Value == Value {
293+
self = withUnsafePointer(to: rule) { pointer in
294+
withUnsafePointer(to: initialValue) { initialValuePointer in
295+
Attribute(body: pointer, value: initialValuePointer) { R._update }
296+
}
297+
}
298+
}
299+
292300
public init<R: StatefulRule>(_ rule: R) where R.Value == Value {
293301
self = withUnsafePointer(to: rule) { pointer in
294302
Attribute(body: pointer, value: nil) { R._update }
295303
}
296304
}
305+
306+
public init<R: StatefulRule>(_ rule: R, initialValue: Value) where R.Value == Value {
307+
self = withUnsafePointer(to: rule) { pointer in
308+
withUnsafePointer(to: initialValue) { initialValuePointer in
309+
Attribute(body: pointer, value: initialValuePointer) { R._update }
310+
}
311+
}
312+
}
297313
}
298314

299315
@_silgen_name("OAGGraphCreateAttribute")

0 commit comments

Comments
 (0)