aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/store-cast.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/store-cast.hh')
-rw-r--r--src/libstore/store-cast.hh16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libstore/store-cast.hh b/src/libstore/store-cast.hh
new file mode 100644
index 000000000..ff62fc359
--- /dev/null
+++ b/src/libstore/store-cast.hh
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "store-api.hh"
+
+namespace nix {
+
+template<typename T>
+T & require(Store & store)
+{
+ auto * castedStore = dynamic_cast<T *>(&store);
+ if (!castedStore)
+ throw UsageError("%s not supported by store '%s'", T::operationName, store.getUri());
+ return *castedStore;
+}
+
+}