Embed Directive in Ada

Here’s the translation of the Go embed directive example to Ada, formatted in Markdown suitable for Hugo:

Our example demonstrates how to include arbitrary files and folders in the Ada binary at build time. This is similar to the concept of resource embedding in other languages.

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Embed_Example is
   -- In Ada, we don't have a direct equivalent to Go's embed directive.
   -- Instead, we can use string constants to simulate embedded content.
   
   File_String : constant String := "Contents of single_file.txt";
   File_Byte : constant String := "Contents of single_file.txt";

   -- For multiple files or folders, we can use a package to organize the content
   package Embedded_Files is
      File1_Hash : constant String := "123";
      File2_Hash : constant String := "456";
   end Embedded_Files;

begin
   -- Print out the contents of 'single_file.txt'
   Put_Line(File_String);
   Put_Line(File_Byte);

   -- Retrieve some files from the embedded folder
   Put_Line(Embedded_Files.File1_Hash);
   Put_Line(Embedded_Files.File2_Hash);
end Embed_Example;

In Ada, we don’t have a direct equivalent to the embed directive. Instead, we can simulate embedded content using string constants or packages to organize multiple embedded files.

To run this example, you would typically use an Ada compiler like GNAT:

$ gnatmake embed_example.adb
$ ./embed_example
Contents of single_file.txt
Contents of single_file.txt
123
456

Note that this Ada version doesn’t actually read from files at compile time. To achieve similar functionality in Ada, you would typically use external resource files and read them at runtime, or use code generation tools to create Ada source files containing the file contents as string constants.

For more complex scenarios involving virtual file systems or large amounts of embedded data, you might need to create custom Ada packages or use third-party libraries that provide similar functionality.