Protocols

The following protocols are available globally.

  • BaggageKeys are used as keys in a Baggage. Their associated type Value guarantees type-safety. To give your BaggageKey an explicit name you may override the name property.

    In general, BaggageKeys should be internal or private to the part of a system using it.

    All access to baggage items should be performed through an accessor computed property defined as shown below:

    /// The Key type should be internal (or private).
    enum TestIDKey: Baggage.Key {
        typealias Value = String
        static var nameOverride: String? { "test-id" }
    }
    
    extension Baggage {
        /// This is some useful property documentation.
        public internal(set) var testID: String? {
            get {
                self[TestIDKey.self]
            }
            set {
                self[TestIDKey.self] = newValue
            }
        }
    }
    

    This pattern allows library authors fine-grained control over which values may be set, and whic only get by end-users.

    See more

    Declaration

    Swift

    public protocol BaggageKey