@@ -41,10 +41,30 @@ impl Builder {
41
41
Builder :: new ( builder)
42
42
}
43
43
44
- // REVIEW: Would probably make this API a bit simpler by taking Into<Option<impl BasicValue>>
45
- // So that you could just do build_return(value) or build_return(None)
46
- // Is that frowned upon?
47
- // TODO: Option<impl BasicValue>
44
+ // REVIEW: Would probably make this API a bit simpler by taking Into<Option<&BasicValue>>
45
+ // So that you could just do build_return(&value) or build_return(None). Is that frowned upon?
46
+ /// Builds a function return instruction. It should be provided with `None` if the return type
47
+ /// is void otherwise `Some(&value)` should be provided.
48
+ ///
49
+ /// # Example
50
+ ///
51
+ /// ```no_run
52
+ /// use inkwell::context::Context;
53
+ ///
54
+ /// // A simple function which returns its argument:
55
+ /// let context = Context::create();
56
+ /// let module = context.create_module("ret");
57
+ /// let builder = context.create_builder();
58
+ /// let i32_type = context.i32_type();
59
+ /// let arg_types = [i32_type.into()];
60
+ /// let fn_type = i32_type.fn_type(&arg_types, false);
61
+ /// let fn_value = module.add_function("ret", fn_type, None);
62
+ /// let entry = fn_value.append_basic_block("entry");
63
+ /// let i32_arg = fn_value.get_first_param().unwrap();
64
+ ///
65
+ /// builder.position_at_end(&entry);
66
+ /// builder.build_return(Some(&i32_arg));
67
+ /// ```
48
68
pub fn build_return ( & self , value : Option < & BasicValue > ) -> InstructionValue {
49
69
let value = unsafe {
50
70
value. map_or_else ( || LLVMBuildRetVoid ( self . builder ) , |value| LLVMBuildRet ( self . builder , value. as_value_ref ( ) ) )
0 commit comments