// Copyright (c) 2017-2022 Cloudflare, Inc. // Licensed under the Apache 2.0 license found in the LICENSE file or at: // https://opensource.org/licenses/Apache-2.0 #pragma once #include #include #include namespace workerd { template inline auto mapAddRef(kj::Maybe>& maybe) -> kj::Maybe> { return maybe.map([](kj::Own& t) { return kj::addRef(*t); }); } template inline auto mapAddRef(kj::Maybe>& maybe) -> kj::Maybe> { return maybe.map([](kj::Rc& t) { return t.addRef(); }); } template inline auto mapAddRef(const kj::Maybe>& maybe) -> kj::Maybe> { return maybe.map([](const kj::Arc& t) { return t.addRef(); }); } template inline auto mapAddRef(kj::Maybe maybe) -> kj::Maybe> { return maybe.map([](T& t) { return kj::addRef(t); }); } template inline auto mapAddRef(kj::ArrayPtr>& array) -> kj::Array> { return KJ_MAP(t, array) { return kj::addRef(*t); }; } template inline auto mapAddRef(kj::Array>& array) -> kj::Array> { return KJ_MAP(t, array) { return kj::addRef(*t); }; } inline auto mapCopyString(const kj::Maybe& string) -> kj::Maybe { return string.map([](const kj::String& s) { return kj::str(s); }); } inline auto mapCopyString(const kj::Maybe& string) -> kj::Maybe { return string.map([](const kj::StringPtr& s) { return kj::str(s); }); } } // namespace workerd